yardpenalty yardpenalty - 23 days ago 10
iOS Question

iOS 10 upgrade causing keydown event errors with bluetooth scanner

Our shop has a scanner device for its web app where we handle the input of the device using jQuery keydown event. This has been working fine except now all older iPhones (4,5,6) seem to have problems with handling the keydown event upon upgrade. What I notice is the + sign and then the enter key is triggered almost simultaneously but most browsers handle this properly...

The processing is triggered when the user hits the ENTER key or the Scanner hits the + key ie:

e.which = 13 || e.which = 187


When I step through the SAFARI debugger the value of the jQuery selector is empty. When the val() of the selector has the actual scanned UPC barcode the iPhone passes the keydown events and the hotkey iOS keyboard is triggered. Since we have it setup for focusout to trigger processing as well the user can hit done on his/her iPhone and put focus back into the selector and scan the next item.

This is hardly a viable solution as our users need to be able to scan continuously on their iPhones. Any suggestions?

Here is a snippet of the code:

$("input[name='SCAN']").on("keydown",function(e) {
var processRegex = /^([0-9]{7,14}\+?)$/;
//on SCAN (last character is a '+/=') field - reload detail section
if (e.which == 13 || e.which == 187){
scan_val = $.trim($("[name='SCAN']").val());
if(processRegex.test(scan_val)){
Handle_Scan(scan_val); //ajax processing function
}
else
$("[name='SCAN']").val('').focus();

return false;
}

return true;
});

Answer

So what happens is the DOM can't catch up with the keydown event! I had to wrap the entire processing logic with a setTimeout(function(){ //handle_scan},250); and presto!

Comments