Browse Source

[FIX] web_responsive: Skip re-search when not writing

When the user uses TAB or SHIFT+TAB to navigate in search results, he can trigger a SHIFT-only keydown event without noticing, which would reset the selected result position to the first or last.

It is disturbing, so, to avoid that problem, the re-search is only triggered if the currently pressed key has length=1 or is Backspace, which will skip most keys that are not actually writing a character into the search input, like i.e. "Shift", "Alt", "F4", etc.

In addition to that, to detect if the search results is empty, the `:empty` selector is not trustable because it considers not empty nodes with whitespace-only content. That has been patched too.
pull/1171/head
Jairo Llopis 6 years ago
parent
commit
e180390ae1
No known key found for this signature in database GPG Key ID: 59564BF1E22F314F
  1. 5
      web_responsive/static/src/js/web_responsive.js

5
web_responsive/static/src/js/web_responsive.js

@ -217,7 +217,7 @@ odoo.define('web_responsive', function (require) {
*/ */
_searchResultsNavigate: function (event) { _searchResultsNavigate: function (event) {
// Exit soon when not navigating results // Exit soon when not navigating results
if (this.$search_results.is(":empty")) {
if (this.$search_results.html().trim() === "") {
// Just in case it is the 1st search // Just in case it is the 1st search
this._searchMenusSchedule(); this._searchMenusSchedule();
return; return;
@ -246,7 +246,10 @@ odoo.define('web_responsive', function (require) {
break; break;
// Other keys trigger a search // Other keys trigger a search
default: default:
// All keys that write a character have length 1
if (key.length === 1 || key === "Backspace") {
this._searchMenusSchedule(); this._searchMenusSchedule();
}
return; return;
} }
// Allow looping on results // Allow looping on results

Loading…
Cancel
Save