When navigating to an autocomplete option with the keyboard and hitting [enter], other browsers (ex: Firefox 14.0.1) fire this event, but chrome (21.0.1180.60 m) does not. I’m using jquery to hook the event:
$('input').keydown(function (event) {
if (event.which == 13) {
var $txt = $(this);
//settimeout req. for firefox to append autocomplete
setTimeout(function () {
//**chrome doesn't get here until you hit enter a second time
}, 0);
}
});
Example here:
http://jsfiddle.net/a9vbe/4/
Anybody know what’s going on here or what a possible solution might be? Using the keyup event instead would ‘fix’ the issue, because computers are faster than fingers, but I would rather not do that. Keydown (or Keypress) are preferable.
Nothing wrong with doing keyup in an instance like this, especially since it fixes the issue. The problem is the data-list doesn’t populate the textbox fast enough for the keydown event to fire off the event on the input. At that point you are still focused within the datalist itself. This is a prime example of one of the benefits of keyup.
Not to mention it will fire off autocomplete once the user releases a key, so you don’t have it firing 1000x because someone holds down the ‘F’ key for no reason.
In ajax / autocomplete situations like this I always use “keyup”.