summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Lempereur <nle@odoo.com>2017-03-24 11:04:21 +0100
committerNicolas Lempereur <nle@odoo.com>2017-03-24 14:07:07 +0100
commit8d948d92350c858e3f5534020968bbfda4c8d154 (patch)
treee1036507561cc239ba71357dfe3d175f4889a36f
parenta82fb281d12c09035d81e3391fc99c91439a9384 (diff)
[FIX] barcodes: fix FieldFloatScannable on firefox
On firefox pressing special keys such as: Left Arrow or Backspace trigger a keypress event. This is different from google chrome which only generate a keydown and keyup event. There was thus two issue when using a FieldFloatScannable and firefox: 1. Keys such as ArrowLeft: would still be catched by FieldFloatScannable and be added programatically to the field but since Odoo didn't fix them a ASCII NUL character (0x0) would be added (in firefox it is represented by a large space). 2. Keys such as Backspace: would still be catched by FieldFloatScannable but were modified and corrected by Odoo so the corresponding ASCII character was added (ASCII BS character (0x8) for backspace). The feature in FieldFloatScannable which add the character is used to add characters for which the browser had been prevented to display them. Thus this fix: - for issue 1 and 2: only use the feature of FieldFloatScannable if the event was previously prevented and the current one is a forgery. - for issue 2: add "Backspace" and "Delete" as specials characters which should not be modified or stopped by the scanner heuristic. opw-706352
-rw-r--r--addons/barcodes/static/src/js/barcode_events.js1
-rw-r--r--addons/barcodes/static/src/js/field_float_scannable.js4
2 files changed, 5 insertions, 0 deletions
diff --git a/addons/barcodes/static/src/js/barcode_events.js b/addons/barcodes/static/src/js/barcode_events.js
index 3c5cb289232..0adff5f8e1b 100644
--- a/addons/barcodes/static/src/js/barcode_events.js
+++ b/addons/barcodes/static/src/js/barcode_events.js
@@ -113,6 +113,7 @@ var BarcodeEvents = core.Class.extend(mixins.PropertiesMixin, {
if (e.key === "ArrowLeft" || e.key === "ArrowRight" ||
e.key === "ArrowUp" || e.key === "ArrowDown" ||
e.key === "Escape" || e.key === "Tab" ||
+ e.key === "Backspace" || e.key === "Delete" ||
/F\d\d?/.test(e.key)) {
return true;
} else {
diff --git a/addons/barcodes/static/src/js/field_float_scannable.js b/addons/barcodes/static/src/js/field_float_scannable.js
index 79022362251..801cf32b5e2 100644
--- a/addons/barcodes/static/src/js/field_float_scannable.js
+++ b/addons/barcodes/static/src/js/field_float_scannable.js
@@ -23,6 +23,10 @@ var FieldFloatScannable = form_widgets.FieldFloat.extend({
},
simulateKeypress: function (e) {
+ /* only simulate a keypress if it has been previously prevented */
+ if (e.originalEvent.dispatched_by_barcode_reader !== true) {
+ return;
+ }
var character = String.fromCharCode(e.which);
var current_str = e.target.value;
var str_before_carret = current_str.substring(0, e.target.selectionStart);