[FIX] web: fix issue with search view input

This patch hopefully solves an annoying issue with the search view:
when the user types really fast (or uses a barcode scanner for example),
the resulting search string was (sometimes) missing the last few
characters.  I'm unclear on the exact reason why it happens.  From the
code, I can only guess that it happens because the scanner use a TAB
key instead of ENTER (TAB is handled in keydown event, ENTER in keyup),
or that the key events aren't in a correct order (if the user press a
key A, then press ENTER, then release ENTER, then release A, it results
in an empty key).

Anyway, the way this patch probably solves the issue is by using the
keypress event for triggering the search view.  I hope that in every
case, the keypress event are correctly ordered.  It leads to some code
I'm not really proud of this patch, but the key event handling are
quite messy.  Also, I need to handle the search string also when the
keyup event is fired, because it might change the search (for example
backspace trigger a keyup, but not a keypress).
This commit is contained in:
Géry Debongnie 2015-03-10 11:27:15 +01:00
parent a8d520552b
commit 1fe4cef530
1 changed files with 12 additions and 4 deletions

View File

@ -2375,12 +2375,20 @@ instance.web.search.AutoComplete = instance.web.Widget.extend({
}
return;
}
if (!self.searching) {
self.searching = true;
return;
var search_string = self.get_search_string();
if (self.search_string !== search_string) {
if (search_string.length) {
self.search_string = search_string;
setTimeout(function () { self.initiate_search(search_string);}, self.delay);
} else {
self.close();
}
}
self.search_string = self.get_search_string();
});
this.$input.on('keypress', function (ev) {
self.search_string = self.get_search_string() + String.fromCharCode(ev.which);
if (self.search_string.length) {
self.searching = true;
var search_string = self.search_string;
setTimeout(function () { self.initiate_search(search_string);}, self.delay);
} else {