From 9d9c80dd6a09e98e7ed55dd709d209d5f6e1fc8c Mon Sep 17 00:00:00 2001 From: s72785 Date: Tue, 21 Jul 2015 21:22:06 +0200 Subject: [PATCH] fix escaping focus fix #67 --- static/js/barcode.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/static/js/barcode.js b/static/js/barcode.js index cd71ad8..9cd6353 100644 --- a/static/js/barcode.js +++ b/static/js/barcode.js @@ -20,16 +20,17 @@ function hideBarcode() { function barcodeKeyPress(event) { var key = String.fromCharCode(event.charCode) var input = document.getElementById('crement') - if ( input ) { + var inputcount = document.querySelectorAll('[type="text"]').length + document.querySelectorAll('[type="number"]').length + if ( input && inputcount == 1 ) { input.focus() } var focused = document.activeElement - if (! focused || focused == document.body) { + if ( !focused || focused == document.body ) { focused = null - } else if (document.querySelector) { + } else if ( document.querySelector ) { focused = document.querySelector(":focus") } - if ( focused == null || focused.tagName != "INPUT" ) { + if ( inputcount <= 1 && ( focused == null || focused.tagName != "INPUT" ) ) { if ( event.keyCode === 13 ) { var input = document.getElementById('barcodeInput') if (input && barcodeBuf.length > 0) {