Hi, wondering if we can set empty string as value for select option?
Django version: 4.0.2
Example
CHOICE_LIST = [
("", "----"),
(1, "Rock"),
(2, "Hard Place"),
]
choices = forms.ChoiceField(
choices=CHOICE_LIST,
required=False,
)
The html generated is same for ("", "----")
and (None, "----")
<select class="form-select form-select-sm mb-2" id="id_choices" name="choices">
<option selected="">----</option>
<option value="1">Rock</option>
<option value="2">Hard Place</option>
</select>
If we use something else instead of ""
or None
for value, it will be what I want:
<select class="form-select form-select-sm mb-2" id="id_choices" name="choices">
<option value="Somethingelse">----</option>
<option value="1">Rock</option>
<option value="2">Hard Place</option>
</select>
Reason I am using ""
is because this field is TextField
Thanks