4

I am very new to Django. I want to create a editable drop down box. After searching I found the below code to create the dropdown list.

Choices1 = [("0", _("0")), ("1", _("1")),("2", _("2"))[("3", _("3"))]

_list =  forms.ChoiceField( choices=choices1,label=_("ListExample"),required=False)

It displays the drop down box. But this is not an editable field. It does not allow me to edit the value , it just allows me to select. I want to make this dropdown/choice filed as editable box.

Thanks, Kalai

Kyle Kelley
  • 13,804
  • 8
  • 49
  • 78
user2905667
  • 83
  • 1
  • 7
  • sorry, what do you mean with 'editable box'?? can you select or write the input? – Leandro Nov 26 '13 at 14:02
  • I need to let users select an item from a dropdown list, but also allow them to instead enter any text, even if it doesn't match an item in the list. I want drop down box similar to below one. http://www.dhtmlgoodies.com/scripts/form_widget_editable_select/form_widget_editable_select.html – user2905667 Nov 26 '13 at 14:09
  • How you solve this problem?! I have the same problem. – Nurzhan Nogerbek Apr 29 '17 at 05:20

2 Answers2

0

maybe you can do:

Choices1 = [("0", _("0")), ("1", _("1")),("2", _("2"))[("3", _("3"))]

options = (value for key, value in Choices1 )

list =  forms.CharField(widget=forms.Textarea(attrs{'selectBoxOptions':';'.join(options)})),label=_("ListExample"),required=False)

in your html, you could try:

<form>
    {{form.as_p}}
</form>


<script type="text/javascript">
    createEditableSelect(document.forms[0].myText);
</script>
Leandro
  • 2,217
  • 15
  • 18
0

For future reference: the solution is now available with html5 which allows editable dropdown list. And so with Django: https://stackoverflow.com/a/32791625/1937033

ThePhi
  • 2,373
  • 3
  • 28
  • 38