chugh97
chugh97

Reputation: 9984

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, ideally 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.

Upvotes: 1

Views: 1852

Answers (2)

jk.
jk.

Reputation: 14435

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

Upvotes: 0

Joakim Johansson
Joakim Johansson

Reputation: 3194

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.

Upvotes: 1

Related Questions