CheckboxSelectMultiple的表单不会验证 [英] form with CheckboxSelectMultiple doesn't validate
问题描述
foo = forms.ChoiceField(widget = forms)我有一个选择字段的表单,它使用了CheckboxSelectMultiple .CheckboxSelectMultiple,
choices =(
(1,ONE),
(2,TWO),
))
该表单呈现两个复选框,但无法验证。
如果我同时选中两个复选框,我会收到一个错误:选择一个有效的选择。 [u'1',u'2']不是可用选项之一
选择一个复选框也不起作用,它给了我:选择一个有效的选择。 [u'1']不是可用的选择之一。
这里发生了什么?
如果您使该字段为forms.MultipleChoiceField而不是forms.ChoiceField,它将会更好地工作。
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?
If you make the field a forms.MultipleChoiceField rather than a forms.ChoiceField it will work better.
这篇关于CheckboxSelectMultiple的表单不会验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!