views:

31

answers:

3

Hi,

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

A: 

That plugin wires itself up to the <input> pretty tightly. If it were my page, I think I'd just have two tags with the same "name", one with autocomplete and one without. When I wanted to toggle between them, I'd make one disabled and hidden, and enable/show the other. (edit oh and also make sure the values of the fields get copied back and forth when they switch)

Pointy
A: 

If you add a class like, say "EnableAC" to your element, you could target that class for autocomplete. When you complete the autocomplete and want to disable it, you remove that class.

Why would do you want to disable the feature though? It may confuse your users if they want to change their selection and the autocomplete doesn't fire.

Rob Allen
I'm not sure that would work, as once the plugin is bound to the `<input>` there are going to remain in place several event handlers.
Pointy
A: 

I've just had a brief look at the js file for the plugin.

There appears to be a javascript line (number 21) during the initialisation of the jquery.autocomplete.js plugin that sets up the originating source input as:

input.autocompleter = me;

Without testing, maybe you could simply then call the following to remove the link between the plugin and the original input?

$('#<your input id>').autocompleter = null;
Brian Scott
That *might* work, but the script also binds a bunch of event handlers.
Pointy
Yeah, like I said, I've not had much of a chance to look into it as I was in a hurry but it might be a good starting point for P Coder to look into. There's no native destroy function in the plugin script that I could see.
Brian Scott