CheckboxSelectMultiple的表单不会验证 [英] form with CheckboxSelectMultiple doesn't validate

查看:193
本文介绍了CheckboxSelectMultiple的表单不会验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆