Reputation: 325
I want to try select my default field in select option forms. My main form here is form
and form.status
gets all user possibility status and user_form.initial.status
gets user current status:
<div class="col-lg-9 select mb-3">
<select name="status" ng-model='discussionsSelect' class="custom-select form-control">
{% for status in form.status %}
<option value="{{user_form.initial.status}}"
{% if status == user_form.initial.status %}selected="selected"{% endif %}>
{{status}}
</option>
{% endfor %}
</select>
</div>
But it is not selected as default.
Upvotes: 2
Views: 1659
Reputation: 5854
You can do it like this:
<select ... name="status">
{% for value, label in form.fields.status.choices %}
<option value="{{ value }}"{% if user_form.status.value == value %} selected{% endif %}>{{ label }}</option>
{% endfor %}
</select>
Upvotes: 3