I am making Django form with an optional select box. I have made a list of tuples per the documentation and have created this field:
MY_CHOICES = [('a', 'a'), ('b', 'b'), ('c', 'c')]
selections = forms.ChoiceField(choices=MY_CHOICES, required=False)
However, the resulting select box does not have an option akin to “—-” or “leave blank.” It merely lists all of the choices even if I specify required=False.
How can I make this select box optional? Should I just add ('', '----') as the first tuple in my list? Thank you.
As you’re not using a
ModelChoiceField, you are explicitly stating the choices you want. You would need to add an empty choice as the first tuple to show an “empty” choice.