Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove an autocomplete once added to an element?

After I add a autocomplete to an element like:

commObj=$("#communityName").autocomplete("auto_commName_backend.php",
                {'onItemSelect': handleItemSelect}, {'extraParams': 'ndo' + ndo});

Is there a way I could disable it or remove the autocomplete for the element dynamically?

I am using modified jquery autocomplete plugin from Dylan Verheul. http://www.pengoworks.com/workshop/jquery/autocomplete_docs.txt

like image 960
P Coder Avatar asked Jun 23 '10 13:06

P Coder


People also ask

How to remove autocomplete jQuery?

The jQuery UI Autocomplete destroy() method is used to remove the autocomplete functionality completely from the widget. This method does not accept any parameter and returns the element back to its pre-init state. Syntax: $( ".

How to remove autocomplete in textbox using jQuery?

Autocomplete attribute of HTML is use to fetch previous input values in input fields. Almost all browsers supports autocomplete attribute, by default this attribute is “on” in html. If you want to disable this attribute ,you can set autocomplete=”off” in html input tag.

Why autocomplete is not working?

If the autocomplete feature is enabled but still not working, try disabling the account sync feature in the You and Google tab as mentioned previously. Click on Turn off to the right of your name and email address. Then restart Google Chrome and enable sync again.


2 Answers

You can remove the autocomplete behaviour by using following line of code:

if (jQuery(control).data('autocomplete')) {
  jQuery(control).autocomplete("destroy");
  jQuery(control).removeData('autocomplete');
}
like image 152
Matloob Ali Avatar answered Sep 22 '22 02:09

Matloob Ali


The easiest and safest way I found is:

$(control).autocomplete({source: []});

Alternatively, as mentioned before this also works:

$(control).autocomplete("destroy");

If you are sure your control has an autocomplete handler set.

like image 33
Paglian Avatar answered Sep 23 '22 02:09

Paglian