Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI Autocomplete: How to get 'change' event to fire earlier?

http://jqueryui.com/demos/autocomplete/#event-change

It sounds like the change event is supposed to fire after you've selected an item, but instead it seems to fire onblur, but only if the input has changed.

select OTOH fires too early, it fires before the input text gets updated.

I want to do something with the input as soon as the user picks an item OR after the user types something and switches focus (like the usual change event).

How can I do that?

like image 521
mpen Avatar asked Jun 20 '11 04:06

mpen


1 Answers

Nevermind, figured it out. We can cheat:

select: function(event,ui) { 
    this.value=ui.item.value; 
    $(this).trigger('change'); 
    return false; 
}

Set the value of the input manually, then trigger the change event manually, and return false so that it doesn't bother setting the input twice.

like image 71
mpen Avatar answered Sep 20 '22 19:09

mpen