Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated the new default value for BooleanFields, clarified the behavi…

…our of

'required' for those fields and updated the examples to use required=False so
that people get the hint. Refs #5104.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6564 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3742e35df34f4a3b31423f0e2676bb873cf45a8e 1 parent e38d54e
Malcolm Tredinnick authored October 20, 2007

Showing 1 changed file with 19 additions and 7 deletions. Show diff stats Hide diff stats

  1. 26  docs/newforms.txt
26  docs/newforms.txt
@@ -100,7 +100,7 @@ Start with this basic ``Form`` subclass, which we'll call ``ContactForm``::
100 100
         subject = forms.CharField(max_length=100)
101 101
         message = forms.CharField()
102 102
         sender = forms.EmailField()
103  
-        cc_myself = forms.BooleanField()
  103
+        cc_myself = forms.BooleanField(required=False)
104 104
 
105 105
 A form is composed of ``Field`` objects. In this case, our form has four
106 106
 fields: ``subject``, ``message``, ``sender`` and ``cc_myself``. We'll explain
@@ -1060,7 +1060,7 @@ fields. We've specified ``auto_id=False`` to simplify the output::
1060 1060
     ...     subject = forms.CharField(max_length=100, help_text='100 characters max.')
1061 1061
     ...     message = forms.CharField()
1062 1062
     ...     sender = forms.EmailField(help_text='A valid e-mail address, please.')
1063  
-    ...     cc_myself = forms.BooleanField()
  1063
+    ...     cc_myself = forms.BooleanField(required=False)
1064 1064
     >>> f = HelpTextContactForm(auto_id=False)
1065 1065
     >>> print f.as_table()
1066 1066
     <tr><th>Subject:</th><td><input type="text" name="subject" maxlength="100" /><br />100 characters max.</td></tr>
@@ -1139,9 +1139,20 @@ For each field, we describe the default widget used if you don't specify
1139 1139
 ~~~~~~~~~~~~~~~~
1140 1140
 
1141 1141
     * Default widget: ``CheckboxInput``
1142  
-    * Empty value: ``None``
  1142
+    * Empty value: ``False``
1143 1143
     * Normalizes to: A Python ``True`` or ``False`` value.
1144  
-    * Validates nothing (i.e., it never raises a ``ValidationError``).
  1144
+    * Validates that the check box is checked (i.e. the value is ``True``) if
  1145
+      the field has ``required=True``.
  1146
+
  1147
+**New in Django development version:** The empty value for a ``CheckboxInput``
  1148
+(and hence the standard ``BooleanField``) has changed to return ``False``
  1149
+instead of ``None`` in the development version.
  1150
+
  1151
+.. note::
  1152
+    Since all ``Field`` subclasses have ``required=True`` by default, the
  1153
+    validation condition here is important. If you want to include a checkbox
  1154
+    in your form that can be either checked or unchecked, you must remember to
  1155
+    pass in ``required=False`` when creating the ``BooleanField``.
1145 1156
 
1146 1157
 ``CharField``
1147 1158
 ~~~~~~~~~~~~~
@@ -1149,7 +1160,8 @@ For each field, we describe the default widget used if you don't specify
1149 1160
     * Default widget: ``TextInput``
1150 1161
     * Empty value: ``''`` (an empty string)
1151 1162
     * Normalizes to: A Unicode object.
1152  
-    * Validates nothing, unless ``max_length`` or ``min_length`` is provided.
  1163
+    * Validates ``max_length`` or ``min_length``, if they are provided.
  1164
+      Otherwise, all inputs are valid.
1153 1165
 
1154 1166
 Has two optional arguments for validation, ``max_length`` and ``min_length``.
1155 1167
 If provided, these arguments ensure that the string is at most or at least the
@@ -1525,7 +1537,7 @@ like so::
1525 1537
         subject = forms.CharField(max_length=100)
1526 1538
         message = forms.CharField()
1527 1539
         senders = MultiEmailField()
1528  
-        cc_myself = forms.BooleanField()
  1540
+        cc_myself = forms.BooleanField(required=False)
1529 1541
 
1530 1542
 Widgets
1531 1543
 =======
@@ -2050,7 +2062,7 @@ have a ``Message`` model that holds each contact submission. Something like::
2050 2062
         subject = models.CharField(max_length=100)
2051 2063
         message = models.TextField()
2052 2064
         sender = models.EmailField()
2053  
-        cc_myself = models.BooleanField()
  2065
+        cc_myself = models.BooleanField(required=False)
2054 2066
 
2055 2067
 You could use this model to create a form (using ``form_for_model()``). You
2056 2068
 could also use existing ``Message`` instances to create a form for editing

0 notes on commit 3742e35

Please sign in to comment.
Something went wrong with that request. Please try again.