jQuery UI Autocomplete .result is not a function woes
Asked Answered
G

2

7

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

Gd answered 15/8, 2011 at 17:45 Comment(3)
Result is not a function of the jQuery library (as you have used it here) and it is not an event of the jQuery UI autocomplete widget. Could you please explain in more detail what you are trying to accomplish here?Supersedure
I've got an <input> tag. I'm getting the autocomplete dropdown like I should, and when I choose one, I want to (for the moment) get an alert with the selected value. How is the way I'm using it different than the example: docs.jquery.com/Plugins/Autocomplete/resultGd
If you are using the plugin documented there, then it is not part of the jQuery UI family of widgets. If you are using jQuery UI's autocomplete widget, then you are not reading the correct documentation for that library. Could you confirm which script you are using?Supersedure
S
10

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);
    }
});
Supersedure answered 15/8, 2011 at 18:7 Comment(1)
I had the same problem for a while. I just realized I've been referencing documentation for a deprecated autocomplete plugin, which had the result function. From what I gather, a lot of people had the same mistake.Embolic
H
0

My error was that I had the file autocomplete-rails.js as well as the provided rails.js in my assets/javascripts folder. Deleting the file was the solution

Hardecanute answered 27/2, 2013 at 17:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.