Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI Autocomplete .result is not a function woes

I've done some searching, and this seems to be a not uncommon problem, but none of the solutions posted seem to be working for me.

I've tried a few different methods:

jQuery(document).ready(function(){
    jQuery( "#on-good-terms-add-term" ).autocomplete({
        source: ongoodtermsavailableTags,
    });

    jQuery( "#on-good-terms-add-term" ).result(function(event, data, formatted) { alert(data); });
});

and

jQuery(document).ready(function(){
    jQuery( "#on-good-terms-add-term" ).autocomplete({
        source: ongoodtermsavailableTags,
    }).result(function(event, data, formatted) {
        alert(data);
    });

});

Both give me the same console error. Would appreciate any assistance. Thanks

like image 365
jdp Avatar asked Aug 15 '11 17:08

jdp


1 Answers

To trigger an event when the user selects a search result with the jQuery UI autocomplete widget, you can initialize your constructor as follows with an event handler for "select":

jQuery("#on-good-terms-add-term").autocomplete({
    source: ongoodtermsavailableTags,
    select: function(e, ui) {
         alert("User selected: " + ui.item.value);
    }
});
like image 163
lsuarez Avatar answered Nov 07 '22 01:11

lsuarez