From abcf1cb36d0bf22d5f2efa4dd85183a0341b33f8 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 30 Jun 2008 10:44:56 +0000 Subject: Fixed #5957 -- Enforce the "required" attribute on BooleanField in newforms. This has been the documented behaviour for ages, but it wasn't correctly implemented. A required BooleanField must be True/checked, since False values aren't submitted. Ideal for things like "terms of service" agreements. Backwards incompatible (since required=True is the default for all fields). Unclear who the original patch was from, but Tai Lee and Alex have kept it up to date recently. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7799 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/fields.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/regressiontests/forms/fields.py b/tests/regressiontests/forms/fields.py index 950b1761a5..c9f3efdbda 100644 --- a/tests/regressiontests/forms/fields.py +++ b/tests/regressiontests/forms/fields.py @@ -937,18 +937,24 @@ ValidationError: [u'This field is required.'] >>> f.clean(True) True >>> f.clean(False) -False +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] >>> f.clean(1) True >>> f.clean(0) -False +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] >>> f.clean('Django rocks') True >>> f.clean('True') True >>> f.clean('False') -False +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] >>> f = BooleanField(required=False) >>> f.clean('') -- cgit v1.3