From 8d948d92350c858e3f5534020968bbfda4c8d154 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Fri, 24 Mar 2017 11:04:21 +0100 Subject: [PATCH] [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 --- addons/barcodes/static/src/js/barcode_events.js | 1 + addons/barcodes/static/src/js/field_float_scannable.js | 4 ++++ 2 files changed, 5 insertions(+) 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);