Form with CheckboxSelectMultiple doesn’t validate

djangodjango-forms

I have a form with a choice field that is using CheckboxSelectMultiple widget:

foo = forms.ChoiceField(widget=forms.CheckboxSelectMultiple,
                        choices=(
                                  ("1", "ONE"),
                                  ("2", "TWO"),
                                 ))

The form renders fine showing two checkboxes, however it doesn't validate.

If I select both checkboxes I am getting an error: Select a valid choice. [u'1', u'2'] is not one of the available choices

Selecting one checkbox doesn't work either, it gives me: Select a valid choice. [u'1'] is not one of the available choices.

What's going on here?

Best Answer

If you make the field a forms.MultipleChoiceField rather than a forms.ChoiceField it will work better.

Related Topic