开发者

jQuery UI 1.8 autocomplete - how to detect change selection

开发者 https://www.devze.com 2023-03-29 17:45 出处:网络
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 th

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

0

精彩评论

暂无评论...
验证码 换一张
取 消