Add global key handler for mobile receiving, for scanner wedge input

this way we don't have to focus the UPC search box, since that seems to
always popup the device keyboard.
This commit is contained in:
Lance Edgar 2017-07-11 13:05:35 -05:00
parent bf3d7b9143
commit 48f5da4511
2 changed files with 26 additions and 6 deletions

View file

@ -102,11 +102,31 @@ $(document).on('click', '#datasync-restart', function() {
});
// handle Enter press for receiving UPC lookup
$(document).on('keydown', '.receiving-upc-search', function(event) {
if (event.which == 13) {
$.mobile.navigate($(this).data('url') + '?upc=' + $(this).val());
// handle global keypress on receiving "row" page, for sake of scanner wedge
$(document).on('keypress', function(event) {
if ($('.ui-page-active [role="main"]').data('route') == 'mobile.receiving.view') {
var upc = $('#upc-search');
if (upc.length) {
if (upc.is(':focus')) {
if (event.which == 13) {
if (upc.val()) {
$.mobile.navigate(upc.data('url') + '?upc=' + upc.val());
}
}
} else {
if (event.which >= 48 && event.which <= 57) { // numeric (qwerty)
upc.val(upc.val() + event.key);
// TODO: these codes are correct for 'keydown' but apparently not 'keypress' ?
// } else if (event.which >= 96 && event.which <= 105) { // numeric (10-key)
// upc.val(upc.val() + event.key);
} else if (event.which == 13) {
if (upc.val()) {
$.mobile.navigate(upc.data('url') + '?upc=' + upc.val());
}
}
return false;
}
}
}
});

View file

@ -94,7 +94,7 @@
</%def>
<%def name="mobile_page_body()">
<div role="main" class="ui-content">
<div role="main" class="ui-content" data-route="${request.matched_route.name}">
% if request.session.peek_flash('error'):
% for error in request.session.pop_flash('error'):