Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Autocomplete: how to refresh list?

I have a form with a variable number of autocomplete fields that use the same select list. These fields are added and removed as needed. Whenever a parameter on the page is changed, I (try to) update the list for all the fields by first calling unbind() then autocomplete() with a new parameter added to the url.

$('input.foo').unbind().autocomplete(url?new_param=bar);

The problem is that unbind() does not seem to be unbinding. When I type in the input field, it fires off the entire history of autocomplete events.

I also tried flushCache to no avail.

How do I clear out the old events?

Thanks.

like image 294
cinematic Avatar asked Oct 17 '09 00:10

cinematic


3 Answers

$(target).autocomplete("destroy");
like image 86
Alvin Gore Avatar answered Sep 20 '22 17:09

Alvin Gore


Try this

$ ('input.foo').unbind('.autocomplete').autocomplete ('url?new_param=bar') ;
like image 30
Rubasu Avatar answered Sep 20 '22 17:09

Rubasu


The autocomplete plugin adds a function called unautocomplete() to remove autocomplete() from fields that have it, so it should work if change your code to:

$('input.foo').unautocomplete().autocomplete('url?new_param=bar');

This unautocomplete() function should remove all of the old events.

like image 40
Deeksy Avatar answered Sep 20 '22 17:09

Deeksy