[FIX] fix autocompletion problems with quick presses
authorGéry Debongnie <ged@odoo.com>
Thu, 20 Nov 2014 09:26:13 +0000 (10:26 +0100)
committerDenis Ledoux <dle@odoo.com>
Fri, 21 Nov 2014 11:04:23 +0000 (12:04 +0100)
Problem was that when the user types quickly in the search bar and press
enter, the keydown event of the enter key happens before the keypress
event of the last key entered.  This means that the autocompletion has
a wrong string.  The fix is to move the enter selection detection from
keydown to keyup.

addons/web/static/src/js/search.js

index 9b15505..e1b96d5 100644 (file)
@@ -2362,6 +2362,12 @@ instance.web.search.AutoComplete = instance.web.Widget.extend({
                 ev.preventDefault();
                 return;
             }
+            if (ev.which === $.ui.keyCode.ENTER) {
+                if (self.current_result && self.get_search_string().length) {
+                    self.select_item(ev);
+                }
+                return;
+            }
             if (!self.searching) {
                 self.searching = true;
                 return;
@@ -2377,7 +2383,6 @@ instance.web.search.AutoComplete = instance.web.Widget.extend({
         this.$input.on('keydown', function (ev) {
             switch (ev.which) {
                 case $.ui.keyCode.TAB:
-                case $.ui.keyCode.ENTER:
                     if (self.current_result && self.get_search_string().length) {
                         self.select_item(ev);
                     }