[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
This commit is contained in:
Nicolas Lempereur
2017-03-24 14:07:07 +01:00
parent a82fb281d1
commit 8d948d9235
2 changed files with 5 additions and 0 deletions
@@ -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 {
@@ -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);