Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

form with CheckboxSelectMultiple doesn't validate

Tags:

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?

like image 911
Sergey Golovchenko Avatar asked Apr 14 '09 02:04

Sergey Golovchenko


1 Answers

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

like image 80
Krystian Cybulski Avatar answered Oct 20 '22 06:10

Krystian Cybulski