jQuery UI 1.8 autocomplete - how to detect change selection
I have a jQuery autocomplete control. On selection the value is stored in a label. If the user then goes back to the autocomplete and changes selection, ide开发者_JAVA技巧ally I would want to clear the value in the label and populate it only when new selection is made. I tried using change event but it fires each time a selection is made.
Have you tried using the .select-event?
From the demo page, http://jqueryui.com/demos/autocomplete/#event-select :
$( ".selector" ).autocomplete({
select: function(event, ui) { ... }
});
It should be triggered once you actually select something, unlike the change event.
Clear the field on focus then blur on select because the autocomplete automatically focuses on select.
$("#searchInput").focus(function(){
$(this).val("");
});
$("#searchInput").autocomplete({
source: source,
minLength: 2,
select: function(event, ui) {
$("#searchInput").blur();
}
});
js fiddle demo
精彩评论