I have enabled the barcode scanner on my site and when I have cursor focus on a link on the page, it gets triggered when the barcode scanner 'Enter' key gets processed. So the barcode rule triggers and works fine, but also my link pops open a new window as if the link were clicked. This link has target="_blank" set. I don't know if that will matter. I was thinking the js code for your module should block the enter keypress for propagating down to the website if it is determined to be a barcode trigger.

Comments

dustinyoder’s picture

This section of code contains a couple additions, that I think will fix this issue. Basically you pass the event to the check_barcode_buffer function and then if we determine this to be a barcode we stopPropagation and preventDefault of the event.

function check_barcode_buffer(e) {
if (barcode.length > settings.min_sku_length) {
e.stopPropagation();
e.preventDefault();
$(document).trigger('barcode_scan', [barcode.join('')]);
barcode = [];
}
}

// Whenever a key is pushed.
$(document).bind('keydown', function(e) {
// Log the time of the keypress.
current_keypress = Date.now();
var char = String.fromCharCode(e.keyCode);
// If the scanner pushed enter, check the buffer.
if (e.keyCode == vk.ENTER) {
check_barcode_buffer(e);

benjy’s picture

Thanks DustinYoder,

Do you want to try and make a patch, some of what you'll need is here: https://drupal.org/node/707484

That way, when the maintainer comes along they can just commit your patch and you'll get the commit credit.