In order for html
to send a field of type select
with multiple values selected it is necessary to put the []
notation in the name attribute of html
:
<select name="categories[]" multiple="multiple" class="form-input__select">
{% for cat in categories %}
<option value="{{ cat.id }}">{{ cat.id }}</option>
{% endfor %}
</select>
How do I capture this value using% django%?
I tried using the:
categories = forms.MultipleChoiceField(required=False)
However when using Form.forms
the value of form.cleaned_data
is empty.
debug before categories[]
:
'categories[]': ['AB', 'AU'], 'brands_are_inclusive': ['true']
debug after cleaned_data
:
'categories': [], 'brands_are_inclusive': 'true'