How To Handle Cases When No Item Selection Is Performed But A String Is Present In The Autocomplete Field?
I am using jQuery UI v1.9. I successfully implemented the jQuery UI Autocomplete widget but I have some trouble when I have to handle cases when a user doesn't select any item from
Solution 1:
You can set a callback function for the change event of autocomplete plugin where you should be able to check if an item has been selected:
$( "#autocomplete" ).autocomplete({
change: function(e,ui){
if(ui.item === null)
alert('No item has been selected')
}
});
UPDATE:
If you want to trigger change event before input loses focus, you could use following code, triggering it on keypress event:
$( "#autocomplete" ).autocomplete({
change: function(e,ui){
if(!ui || ui.item === null)
console.log('No item has been selected')
}
}).on('keypress',function(){$(this).autocomplete('option','change').call()});
Post a Comment for "How To Handle Cases When No Item Selection Is Performed But A String Is Present In The Autocomplete Field?"