#20982: forms.BooleanField field issue
---------------------------+--------------------------------------
     Reporter:  george.li  |                    Owner:  nobody
         Type:  Bug        |                   Status:  closed
    Component:  Forms      |                  Version:  1.7
     Severity:  Normal     |               Resolution:  worksforme
     Keywords:             |             Triage Stage:  Unreviewed
    Has patch:  1          |      Needs documentation:  0
  Needs tests:  0          |  Patch needs improvement:  0
Easy pickings:  0          |                    UI/UX:  0
---------------------------+--------------------------------------

Comment (by abhillman):

 It seems to me that the original thinking on this was the following:
 making a boolean field required is good for cases where a user must, say,
 check a box to accept terms of service. This seems to me, however, that it
 should be handled at the form-level clean or with a custom validator on
 the field — not by setting required=False. Another argument is that
 BooleanField is one of the only fields that overrides forms.Field's
 validate method. Whereas the other fields rely on self.empty_values,
 forms.BooleanField is the only field that relies on the provided value's
 implicit boolean value. Definitely inconsistent.

 But again, I understand completely if this is a backwards compatibility
 case. It just is terribly confusing in many cases, especially when wanting
 to, say, use forms for validating some JSON data. Say you always want a
 boolean field to show up in the data, then, really, the best way to deal
 with this situation is to sub-class BooleanField and override its validate
 method. Or write a custom validator — but its a bit hacky to circularly
 reference the calling class' empty_values from an outside method.

 Again, I understand your reasoning to some degree. It IS in fact
 documented, if otherwise confusing.

--
Ticket URL: <https://code.djangoproject.com/ticket/20982#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.2322e9efe4024a74bb51be1fcd54eb57%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to