﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
5957	unchecked BooleanField does not raise ValidationError even if it is required	che@…	Alex Gaynor	"I'm afraid that required=True doesn't quite work on newforms' [http://www.djangoproject.com/documentation/newforms/#booleanfield BooleanField]. According to the docs, it should trigger an error in case the field is unchecked, but it doesn't. I suspect the reason is that [http://code.djangoproject.com/changeset/6563 changeset 6563] altered return value of CheckboxInput from None to False in unchecked cases, but ""required"" check of the BooleanField still relies on default ""None_to_ValidationError"" method of its parent class.

== trunk rev 6678 ==
{{{
>>> import django.newforms as forms
>>> class MyForm(forms.Form):
...   bfield = forms.BooleanField(required=True)
...
>>> f = MyForm({})
>>> f.is_valid()
True
}}}

== trunk rev 6562 ==
{{{
>>> import django.newforms as forms
>>> class MyForm(forms.Form):
...   bfield = forms.BooleanField(required=True)
...
>>> f = MyForm({})
>>> f.is_valid()
Traceback (most recent call last):
  File ""<stdin>"", line 1, in ?
  File ""/usr/lib/python2.4/site-packages/django/newforms/forms.py"", line 106, in is_valid
    return self.is_bound and not bool(self.errors)
  File ""/usr/lib/python2.4/site-packages/django/newforms/forms.py"", line 97, in _get_errors
    self.full_clean()
  File ""/usr/lib/python2.4/site-packages/django/newforms/forms.py"", line 192, in full_clean
    value = field.clean(value)
  File ""/usr/lib/python2.4/site-packages/django/newforms/fields.py"", line 454, in clean
    super(BooleanField, self).clean(value)
  File ""/usr/lib/python2.4/site-packages/django/newforms/fields.py"", line 93, in clean
    raise ValidationError(ugettext(u'This field is required.'))
  File ""/usr/lib/python2.4/site-packages/django/utils/translation/__init__.py"", line 62, in ugettext
    return real_ugettext(message)
  File ""/usr/lib/python2.4/site-packages/django/utils/translation/__init__.py"", line 32, in delayed_loader
    if settings.USE_I18N:
  File ""/usr/lib/python2.4/site-packages/django/conf/__init__.py"", line 28, in __getattr__
    self._import_settings()
  File ""/usr/lib/python2.4/site-packages/django/conf/__init__.py"", line 55, in _import_settings
    raise EnvironmentError, ""Environment variable %s is undefined."" % ENVIRONMENT_VARIABLE
EnvironmentError: Environment variable DJANGO_SETTINGS_MODULE is undefined.
}}}
(Maybe I should have run this in django shell, but we can still see that ValidationError got raised.)

== trunk rev 6563 ==
{{{
>>> import django.newforms as forms
>>> class MyForm(forms.Form):
...   bfield = forms.BooleanField(required=True)
...
>>> f = MyForm({})
>>> f.is_valid()
True
}}}
(After changeset 6563, unchecked field is valid even if required.)

== trunk rev 6678, with patch ==
{{{
>>> import django.newforms as forms
>>> class MyForm(forms.Form):
...   bfield = forms.BooleanField(required=True)
...
>>> f = MyForm({})
>>> f.is_valid()
False
}}}
(Supplied patch seems to fix the issue.)"		closed	Forms	dev		fixed		real.human@…	Ready for checkin	1	0	0	0	0	0
