When using the jquery autocomplete plugin, what do you do when the user does not select an item in the list, but instead types a valid value and tabs away?
eg when the auto complete list contains:
Cat
Dog
Fish
And the user types cat, but does not select Cat from the autocomplete’s dropdown list and instead tabs away. Because they did not select any item from the list, the autocomplete select event does not fire, and we lose the chance to respond to it:
$('#Animal').autocomplete({
source: url,
minlength: 1,
select: function (event, ui) {
$("#Animal").val(ui.item.value);
changeUsersAnimal(ui.item.id);
}
});
How do I handle this case?
You’re probably looking for Scott González’
autoSelectextension. Just including this extension on the page will allow theselectevent to fire if the user enters a valid value and should require no changes on your end:Here’s an example using the extension: http://jsfiddle.net/vFWUt/226/