From ab75e0a8ca8135786f4740c2eeb88a6a1720c871 Mon Sep 17 00:00:00 2001
From: Benjamin Bertrand <benjamin.bertrand@esss.se>
Date: Tue, 20 Feb 2018 16:10:21 +0100
Subject: [PATCH] Prevent the window to scroll when selecting the submit button

If we scroll to the submit button, we can't see the "Submit" QRCode
---
 app/static/js/create_item.js | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/app/static/js/create_item.js b/app/static/js/create_item.js
index 76e3ded..008bbcd 100644
--- a/app/static/js/create_item.js
+++ b/app/static/js/create_item.js
@@ -1,5 +1,12 @@
 $(document).ready(function() {
 
+  $.fn.focusWithoutScrolling = function(){
+    var x = window.scrollX, y = window.scrollY;
+    this.focus();
+    window.scrollTo(x, y);
+    return this; //chainability
+  };
+
   // Focus to ICS id when loading the page
   $("#ics_id").focus();
 
@@ -19,10 +26,9 @@ $(document).ready(function() {
   // Focus on the submit button so that scanning the Submit action
   // will submit the form (due to the CR sent by the scanner)
   $("#serial_number").keydown(function(event) {
-    console.log(event.keyCode);
     if(event.keyCode == 13) {
       event.preventDefault();
-      $("#submit").focus();
+      $("#submit").focusWithoutScrolling();
       return false;
     }
   });
-- 
GitLab