Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery autocomplete change event not being fired

I am trying to conditionally change a link URL whenever someone enters a value in a JQuery autocomplete search field, however, using the following code I cannot for some reason either register the change event or even bind a handler:

 $("#protocol-name").autocomplete({
    source: protocol_names,
}).bind( "autocompletechange", function(){
    alterURL();
 }).focus(function() {
    $(this).select();
    $(this).autocomplete('search');
});

Additionally, $("#procotol-name").change() registers nothing either, where protocol-name represents an input field.

like image 702
user638756 Avatar asked Mar 01 '11 04:03

user638756


2 Answers

Try to do like this:

$( ".selector" ).autocomplete({
   change: function(event, ui) { ... }
});
like image 174
Shiva Srikanth Thummidi Avatar answered Oct 27 '22 00:10

Shiva Srikanth Thummidi


In fact change event is fired, but only after input element has lost its focus. You can check it yourself.

UPD: this behaviour is inconsistent across browsers, see http://bugs.jqueryui.com/ticket/8878

like image 29
Nash Bridges Avatar answered Oct 27 '22 01:10

Nash Bridges