From 5e11d8f4681c25e5312fd267e48fe696e14c31e5 Mon Sep 17 00:00:00 2001
From: Benjamin Bertrand <benjamin.bertrand@esss.se>
Date: Fri, 9 Feb 2018 10:00:00 +0100
Subject: [PATCH] Prevent enter key to submit the form

We don't want to submit the form when scanning a code bar or ICS id.
In keyboard mode, the scanner sends a CR as last character.
---
 app/static/js/create_item.js | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/app/static/js/create_item.js b/app/static/js/create_item.js
index bd7f848..64f2bad 100644
--- a/app/static/js/create_item.js
+++ b/app/static/js/create_item.js
@@ -1,5 +1,16 @@
 $(document).ready(function() {
 
+  // Prevent enter key to submit the form
+  // When scanning a code bar, the scanner usually
+  // send a CR as last character. We don't want that
+  // to submit the form.
+  $(window).keydown(function(event) {
+    if(event.keyCode == 13) {
+      event.preventDefault();
+      return false;
+    }
+  });
+
   // Focus to ICS id when loading the page
   $("#ics_id").focus();
 
-- 
GitLab