Opened 17 years ago
Closed 17 years ago
#6156 closed (duplicate)
Boolean field should force checking, but it is not.
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Uncategorized | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Documentation says:
- Empty value: False
- Validates that the check box is checked (i.e. the value is True) if the field has required=True
Note
Since all Field subclasses have required=True by default, the validation condition here is important. If you want to include a checkbox in your form that can be either checked or unchecked, you must remember to pass in required=False when creating the BooleanField.
But:
>>> from django.newforms import * >>> class F(Form): >>> foo = BooleanField(required=True) >>> f = F(data={}) # AFAIK if checkinput is not check then browser doesn't send anything in data >>> f.is_valid() # should be False with errors that foo field is required True >>> print f.cleaned_data['foo'] False
checked on version SVN r6670.
Note:
See TracTickets
for help on using tickets.
That is the cause of this error:
Documentation says:
but require condition in Field.clean() (called by BooleanField.clean).
and EMPTY_VALUES=(None, )
because we got False from widget CheckboxInput: