In Django BooleanFields, the required flag is used to mean that the field
must be checked for the form to validate. Required is True by default for
all Fields, so this is the default behavior.
I strongly suspect that this violates principle of least surprise for most
people including Boolean Fields in forms. It did for me.
I've patched it in my local Django checkout. I realize this is a
backwards-incompatible change, so it might not be eligible for trunk any
time soon, but FWIW, here's the patch:
--- i/django/forms/fields.py
+++ w/django/forms/fields.py
@@ -606,6 +606,11 @@ class URLField(CharField):
class BooleanField(Field):
widget = CheckboxInput
+ def __init__(self, *args, **kwargs):
+ if not args and 'required' not in kwargs:
+ kwargs['required'] = False
+ return super(BooleanField, self).__init__(*args, **kwargs)
+
def to_python(self, value):
"""Returns a Python boolean object."""
# Explicitly check for the string 'False', which is what a hidden
field
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.