(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.
Before this commit, it wasn't possible to use a barcode scanner
with the Odoo mobile app.
However it works fine for mobile Chrome browsers.
We now know that 'keypress' event doesn't work as expected in
Chrome for mobile. See @3a74afd21
It's why 'keydown' detection has been implemented.
We also want to use this detection in our Android app.
Unfortunately, 'window.chrome' doesn't seem to exist anymore
in the Android webview.
In this commit, we change the way Chrome is detected.
Before this commit, you were automatically redirected to the top of
the page when you scanned a product.
It was, therefore, difficult to find the product that had just been
scanned and to check its quantity.
Because of @3a74afd21 we need to put the focus in an invisible input
at the top of the page.
This input is now always vertically centered in the middle of the page.
The notification manager was removed and replaced by a notification
service. Some tests were forward ported after this change, so they need
to be updated to the new system.
The check on the event target and the barcode target is done outside
the check on barcode found. That result in a warning for each modal/form
view that is pending.
This commit do the check before doing any operations in order
to directly stop if the event target is not similiar to listening
barcode target
The barcode scanner and the quantity listener do not use
the same proccess although they act for the same operation.
(For example the quantity listener trigger onchange server side
while the barcode scanner not if 'notifychange' key on the
active_barcode is set to False)
Since quantity listener is based on candidate we could directly
call the _barcodeSelectedCandidate method in order to have a common
behavior and code.
Before this commit, the barcode value wasn't triggered on
some Android devices with Google Chrome and using the Odoo app.
In fact, the keypress event may not trigger with some devices.
This is probably due to the fact that this event is marked as
'Legacy'.
See: https://www.w3.org/TR/uievents/#legacy-keyboardevent-event-types
To fix this, we can use 'keydown' event but we have to handle an
other issue: there is no way to know which key is typed.
The auto-suggest feature on Android invalidate all the following
properties: Keycode, charCode, key, which, keyIdentifier, code.
This is a well-known issue:
https://bugs.chromium.org/p/chromium/issues/detail?id=118639
For more infos, please read this blog:
https://www.outsystems.com/blog/javascript-events-unmasked-how-to-create-input-mask-for-mobile.html
As a work around, we create a temporary input field that stores
the barcode value.
The focus is set on this input when a keydown is detected.
Note that when an input has the focus, the android virtual keyboard
will be opened. We can't avoid this behavior.
The only thing we can do is to automatically close it after 800 ms.
See: https://bugs.chromium.org/p/chromium/issues/detail?id=662386
As this fix is specific for Chrome only, it's not possible
to test it easily. Some tests will be added in master.
This fixes an issue occurring with Firefox.
Some events was buffered with an undefined value and it wasn't
possible to build the barcode value from these events.
See 'handle_buffered_keys' function.
So now, we simply skip this kind of event.
We consider this as 'special keys'.
Allow the user to set the quantity with barcode
scanning. This functionality was present in v9 but
didn't work in v11.
The code in order to make it work was already present in
_quantityListener however it makes a check on setQuantityWithKeypress
key on the obejct activeBarcode. Howver the key was never set during the
activeBarcode event.
This commit set the key on the activeBarcode if passed in the event data.
It also allow to trigger a barcode if the user is inside a modal.