Dynamically disable the autocomplete feature

165 views
Skip to first unread message

Domenico Testa

unread,
May 7, 2013, 9:46:20 AM5/7/13
to django-s...@googlegroups.com
Any chances to dynamically change the input behaviour using javascript?
I would like to "deactivate" the input changing it into a normal text field. Any suggestions?

Thanks in advance.

Mark Lavin

unread,
May 7, 2013, 10:08:12 AM5/7/13
to django-s...@googlegroups.com
Yes you can deactivate the autocompletion with the destroy method inherited from the base jQuery UI plugin: http://api.jqueryui.com/autocomplete/#method-destroy

$('#field_id').djselectable('destroy');

Likewise you can change any of the options using option: http://api.jqueryui.com/autocomplete/#method-option


--
You received this message because you are subscribed to the Google Groups "django-selectable" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-selecta...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Domenico Testa

unread,
May 8, 2013, 12:10:17 PM5/8/13
to django-s...@googlegroups.com
Let me give you some more context.
I have a django form with some AutoCompleteSelectField. Some of them are chained with the "prepareQuery" technique.
After form validation i save in the django model a string coming from the lookup item, not a model instance.
When i select a particular value on a master AutoCompleteSelectField i need to disable autocompletion on the dependant field and enabling free text input.
I don't need to create new lookup values, i just need that field behave like a normal CharField.
Now, if i call djselectable.option("option", "allowNew", true) i can input freely the text i want, but the hidden field is not synced with the text input, causing a missing required field validation error on the server side.

Could you suggest me a "right" approach?

Mark Lavin

unread,
May 8, 2013, 2:41:05 PM5/8/13
to django-s...@googlegroups.com
If you aren't selecting a model instance then AutoCompleteSelectField doesn't seem like the appropriate field to use. Instead the form should just have a CharField and use the AutoCompleteWidget.

Domenico Testa

unread,
May 9, 2013, 6:06:17 PM5/9/13
to django-s...@googlegroups.com
I've managed to replace the AutoCompleteField with a CharField(widget=AutoCompleteWidget...). Then i used .djselectable('option', 'disabled', true) in Javascript to disable autocomplete as needed.

Great package, thank you.

2013/5/8 Mark Lavin <markd...@gmail.com>
Reply all
Reply to author
Forward
0 new messages