#23580: forms.fields.NullBooleanField does not honor required=True
-------------------------------+--------------------
     Reporter:  jdufresne      |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  Forms          |    Version:  master
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 I use `forms.fields.NullBooleanField` to allow a user to select Yes, No or
 Unknown (Unknown may also mean "no answer"). Sometimes -- depending on the
 site configuration -- this field should be required, other times not. In
 this case, required means that either Yes or No should be selected. The
 field should *not* be left blank (Unknown or "no answer"). Currently, when
 `required=True` is set, `forms.fields.NullBooleanField.validate()` does
 nothing and will simply validate all values.

 I can't use `forms.fields.BooleanField` because when `required=True` is
 set Yes *must* be selected for the field to validate.

 This topic has come up in the past: <https://groups.google.com/d/msg
 /django-developers/eN7FvAvTsew/kLQ4FdE3fWAJ>

 I propose `forms.fields.NullBooleanField` be altered to handle required.
 That is change validate to:

 {{{
     def validate(self, value):
         if value is None and self.required:
             raise ValidationError(....
 }}}

 I'll happily create a pull request to achieve this. One concern will be
 backwards compatibility. But seeing as how `required=True` had no effect
 on the field originally, I see no reason anyone would set it and expect
 something useful other than what has been suggested above.

--
Ticket URL: <https://code.djangoproject.com/ticket/23580>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.1e13a061a936cca868708095139c46c7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to