From 769e58d186c945f5d2bbb61061bf7fc1f2a662f7 Mon Sep 17 00:00:00 2001 From: Arthur Maniet Date: Tue, 15 Sep 2015 13:20:59 +0200 Subject: [PATCH] [FIX] barcodes: don't require suffix for scans Users don't have to configure their scanner. As stated in the docs/planner, either wait 50ms between 2 scans or use a suffix. --- addons/barcodes/doc/index.rst | 2 +- addons/barcodes/static/src/js/barcode_events.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/barcodes/doc/index.rst b/addons/barcodes/doc/index.rst index 536c22efd15..6c93b1f0283 100644 --- a/addons/barcodes/doc/index.rst +++ b/addons/barcodes/doc/index.rst @@ -95,7 +95,7 @@ The purpose of this component is to listen to keypresses to detect barcodes, the on core.bus inside a 'barcode_event'. All keypress events are buffered until there is no more keypress during 50ms or a carriage return / tab is inputted (because most barcode scanners use this as a suffix). -If the buffered keys looks like a barcode (match the the regexp /.{3,}[\n\r\t]+), an event is triggered : +If the buffered keys looks like a barcode (match the the regexp /.{3,}[\n\r\t]*), an event is triggered : core.bus.trigger('barcode_scanned', barcode); Otherwise, the keypresses are 'resent'. However, for security reasons, a keypress event programmatically crafted doesn't trigger native browser behaviors. For this reason, BarcodeEvents doesn't intercept keypresses diff --git a/addons/barcodes/static/src/js/barcode_events.js b/addons/barcodes/static/src/js/barcode_events.js index 5059d4a5541..9ca93c18f3f 100644 --- a/addons/barcodes/static/src/js/barcode_events.js +++ b/addons/barcodes/static/src/js/barcode_events.js @@ -10,7 +10,7 @@ var BarcodeEvents = core.Class.extend(mixins.PropertiesMixin, { buffered_key_events: [], // Regexp to match a barcode input and extract its payload // Note: to build in init() if prefix/suffix can be configured - regexp: /(.{3,})[\n\r\t]+/, + regexp: /(.{3,})[\n\r\t]*/, // By knowing the terminal character we can interpret buffered keys // as a barcode as soon as it's encountered (instead of waiting x ms) suffix: /[\n\r\t]+/,