Django BooleanField Checkbox Returns Empty

38 views
Skip to first unread message

Ken Nguyen

unread,
Apr 29, 2015, 12:44:45 PM4/29/15
to django...@googlegroups.com
I read every corner of the documentation but couldn't figure out why the BooleanField Form doesn't return 'True' when the checkbox is checked. Is this a valid test? Shouldn't formset.cleaned_data = [{True}, {False}]?



>>> from django import forms
>>> from django.forms.formsets import formset_factory
>>>
>>> class CheckBox (forms.Form):
...    overwrite = forms.BooleanField (required = False)
...
>>>
>>> data = {
...     'form-TOTAL_FORMS': '2',
...     'form-INITIAL_FORMS': '0',
...     'form-MAX_NUM_FORMS': '3',
...     'checkbox-0-overwrite': True,
...     'checkbox-1-overwrite': False,
...}
>>>
>>> CheckboxFormSet = formset_factory (CheckBox)
>>> formset = CheckboxFormSet (data)
>>> formset.is_valid ()
True
>>> formset.cleaned_data
[{}, {}]
>>>


Reply all
Reply to author
Forward
0 new messages