From a30d9aa560244cf7cf01bf1054a7bece2fb08ea7 Mon Sep 17 00:00:00 2001 From: Adrien Dieudonne Date: Wed, 9 May 2018 11:32:16 +0200 Subject: [PATCH] [FIX] barcodes: avoid virtual keyboard to show up while scanning barcode (1) Before this commit, the input barcode was removed from the dom after each scan but now we want to keep it focused to avoid to automatically open the virtual keyboard in mobile. This behavior will be useful in enterprise only. Another commit will follow in this repository. As the input is not removed anymore, we had to disable autocomplete to hide previous entries as suggestions. (2) We also add z-index property to avoid to click on the hidden input located in the middle of the page. --- .../barcodes/static/src/js/barcode_events.js | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/addons/barcodes/static/src/js/barcode_events.js b/addons/barcodes/static/src/js/barcode_events.js index a2e5808f8be..2d602a36b97 100644 --- a/addons/barcodes/static/src/js/barcode_events.js +++ b/addons/barcodes/static/src/js/barcode_events.js @@ -64,12 +64,14 @@ var BarcodeEvents = core.Class.extend(mixins.PropertiesMixin, { 'position': 'fixed', 'top': '50%', 'transform': 'translateY(-50%)', - 'opacity': 0, + 'z-index': '-1', }, }); + // Avoid to show autocomplete for a non appearing input + this.$barcodeInput.attr('autocomplete', 'off'); } - this.__removeBarcodeField = _.debounce(this._removeBarcodeField, this.inputTimeOut); + this.__blurBarcodeInput = _.debounce(this._blurBarcodeInput, this.inputTimeOut); }, handle_buffered_keys: function() { @@ -232,7 +234,7 @@ var BarcodeEvents = core.Class.extend(mixins.PropertiesMixin, { this.max_time_between_keys_in_ms); } // if the barcode input doesn't receive keydown for a while, remove it. - this.__removeBarcodeField(); + this.__blurBarcodeInput(); } }, @@ -247,21 +249,22 @@ var BarcodeEvents = core.Class.extend(mixins.PropertiesMixin, { var barcodeValue = this.$barcodeInput.val(); if (barcodeValue.match(this.regexp)) { core.bus.trigger('barcode_scanned', barcodeValue, $(e.target).parent()[0]); - this.$barcodeInput.val(''); + this._blurBarcodeInput(); } }, /** - * Remove the temporary input created to store the barcode value. - * If nothing happens, this input will be removed, so the focus will be lost - * and the virtual keyboard on mobile devices will be closed. + * Removes the value and focus from the barcode input. + * If nothing happens, the focus will be lost and + * the virtual keyboard on mobile devices will be closed. * * @private */ - _removeBarcodeField: function () { + _blurBarcodeInput: function () { if (this.$barcodeInput) { - // Reset the value and remove from the DOM. - this.$barcodeInput.val('').remove(); + // Close the virtual keyboard on mobile browsers + // FIXME: actually we can't prevent keyboard from opening + this.$barcodeInput.val('').blur(); } },