fix backspace, limit input
to non control/alt key, so shortcuts can still be used in browser also F-Keys now are useable again
This commit is contained in:
parent
9d9c80dd6a
commit
a4b42c99c9
1 changed files with 23 additions and 16 deletions
|
@ -17,11 +17,11 @@ function hideBarcode() {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
function barcodeKeyPress(event) {
|
function barcodeKeyPress( event ) { // takes input from either keyboard or barcode scanner
|
||||||
var key = String.fromCharCode( event.charCode )
|
var key = String.fromCharCode( event.charCode )
|
||||||
var input = document.getElementById( 'crement' )
|
var input = document.getElementById( 'crement' )
|
||||||
var inputcount = document.querySelectorAll( '[type="text"]' ).length + document.querySelectorAll( '[type="number"]' ).length
|
var inputcount = document.querySelectorAll( '[type="text"]' ).length + document.querySelectorAll( '[type="number"]' ).length
|
||||||
if ( input && inputcount == 1 ) {
|
if ( input && inputcount == 1 ) { // focus in 'crement' when no other input fields only
|
||||||
input.focus()
|
input.focus()
|
||||||
}
|
}
|
||||||
var focused = document.activeElement
|
var focused = document.activeElement
|
||||||
|
@ -30,8 +30,11 @@ function barcodeKeyPress(event) {
|
||||||
} else if ( document.querySelector ) {
|
} else if ( document.querySelector ) {
|
||||||
focused = document.querySelector( ":focus" )
|
focused = document.querySelector( ":focus" )
|
||||||
}
|
}
|
||||||
if ( inputcount <= 1 && ( focused == null || focused.tagName != "INPUT" ) ) {
|
if (
|
||||||
if ( event.keyCode === 13 ) {
|
!event.ctrlKey && !event.altKey // no hotkeys used
|
||||||
|
&& ( focused == null || focused.tagName != "INPUT" ) // focus not in input fielf for manual input
|
||||||
|
) {
|
||||||
|
if ( event.keyCode === 13 ) { // carriage return
|
||||||
var input = document.getElementById( 'barcodeInput' )
|
var input = document.getElementById( 'barcodeInput' )
|
||||||
if ( input && barcodeBuf.length > 0 ) {
|
if ( input && barcodeBuf.length > 0 ) {
|
||||||
input.setAttribute( 'value', barcodeBuf )
|
input.setAttribute( 'value', barcodeBuf )
|
||||||
|
@ -40,16 +43,20 @@ function barcodeKeyPress(event) {
|
||||||
}
|
}
|
||||||
barcodeBuf = ""
|
barcodeBuf = ""
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
} else if ( event.keyCode === 27 ){
|
} else if ( event.keyCode === 27 ) { // escape
|
||||||
|
console.log( "escape" )
|
||||||
barcodeBuf=hideBarcode()
|
barcodeBuf=hideBarcode()
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
} else if ( event.keyCode === 9 ){
|
} else if ( event.keyCode === 8 ) { // backspace
|
||||||
|
console.log( "backspace" )
|
||||||
barcodeBuf = barcodeBuf.substring( 0, barcodeBuf.length - 1 )
|
barcodeBuf = barcodeBuf.substring( 0, barcodeBuf.length - 1 )
|
||||||
|
showBarcode( barcodeBuf )
|
||||||
if ( barcodeBuf.length <= 0 ) {
|
if ( barcodeBuf.length <= 0 ) {
|
||||||
barcodeBuf = hideBarcode()
|
barcodeBuf = hideBarcode()
|
||||||
}
|
}
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
} else {
|
} else if ( event.keyCode == 0 ) { // e.g. F-Keys are 112 to 123, A-Za-z0-9 all are 0.
|
||||||
|
console.log( "some input: " + barcodeBuf + "[" + key + "] <= {" + event.keyCode + "}" )
|
||||||
barcodeBuf += key
|
barcodeBuf += key
|
||||||
showBarcode( barcodeBuf )
|
showBarcode( barcodeBuf )
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
|
Loading…
Reference in a new issue