So the problem is the autocomplete combobox is initialized without the change event. I want to bind it afterwards but the documentation seems to be inadequate about the combobox.
Code that doesn't work:
$('#select').combobox();
...
$('#select').bind( "autocompletechange", function(event, ui) {
alert('changed');
});
I am guessing the event label is wrong since the inline label on the combobox is "selected" e.g. $('#s开发者_Go百科elect').combobox({selected : function(ev,ui) { alert('selected'); }});
works but I can't use it that way.
So any idea what's the correct label of the event? I just can't find it in the documentation.
EDIT: Actually I found where my problem was. $('#select').combobox();
just maps a select to an autocomplete input. The input it creates has an id like id='select-autocomplete'
, so to bind and event to that combobox - the selector should be on this input instead on the select. So the working code:
$('#select').combobox();
...
$('#select-autocomplete').bind( "autocompletechange", function(event, ui) {
alert('changed');
});
So, I found more clear solution than binding event to created .ui-combobox-input. You should find in combobox code place where input is initialized, and find select parameter. Make changes in this part of code:
select: function( event, ui ) {
ui.item.option.selected = true;
that._trigger( "selected", event, {
item: ui.item.option
});
that.element.trigger('change');// here is the trick
},
精彩评论