Author: mtredinnick
Date: 2007-10-20 07:21:16 -0500 (Sat, 20 Oct 2007)
New Revision: 6564
Modified:
django/trunk/docs/newforms.txt
Log:
Updated the new default value for BooleanFields, clarified the behaviour of
'required' for those fields and updated the examples to use required=False so
that people get the hint. Refs #5104.
Modified: django/trunk/docs/newforms.txt
===================================================================
--- django/trunk/docs/newforms.txt 2007-10-20 12:21:07 UTC (rev 6563)
+++ django/trunk/docs/newforms.txt 2007-10-20 12:21:16 UTC (rev 6564)
@@ -100,7 +100,7 @@
subject = forms.CharField(max_length=100)
message = forms.CharField()
sender = forms.EmailField()
- cc_myself = forms.BooleanField()
+ cc_myself = forms.BooleanField(required=False)
A form is composed of ``Field`` objects. In this case, our form has four
fields: ``subject``, ``message``, ``sender`` and ``cc_myself``. We'll explain
@@ -1060,7 +1060,7 @@
... subject = forms.CharField(max_length=100, help_text='100
characters max.')
... message = forms.CharField()
... sender = forms.EmailField(help_text='A valid e-mail address,
please.')
- ... cc_myself = forms.BooleanField()
+ ... cc_myself = forms.BooleanField(required=False)
>>> f = HelpTextContactForm(auto_id=False)
>>> print f.as_table()
<tr><th>Subject:</th><td><input type="text" name="subject" maxlength="100"
/><br />100 characters max.</td></tr>
@@ -1139,17 +1139,29 @@
~~~~~~~~~~~~~~~~
* Default widget: ``CheckboxInput``
- * Empty value: ``None``
+ * Empty value: ``False``
* Normalizes to: A Python ``True`` or ``False`` value.
- * Validates nothing (i.e., it never raises a ``ValidationError``).
+ * Validates that the check box is checked (i.e. the value is ``True``) if
+ the field has ``required=True``.
+**New in Django development version:** The empty value for a ``CheckboxInput``
+(and hence the standard ``BooleanField``) has changed to return ``False``
+instead of ``None`` in the development version.
+
+.. note::
+ Since all ``Field`` subclasses have ``required=True`` by default, the
+ validation condition here is important. If you want to include a checkbox
+ in your form that can be either checked or unchecked, you must remember to
+ pass in ``required=False`` when creating the ``BooleanField``.
+
``CharField``
~~~~~~~~~~~~~
* Default widget: ``TextInput``
* Empty value: ``''`` (an empty string)
* Normalizes to: A Unicode object.
- * Validates nothing, unless ``max_length`` or ``min_length`` is provided.
+ * Validates ``max_length`` or ``min_length``, if they are provided.
+ Otherwise, all inputs are valid.
Has two optional arguments for validation, ``max_length`` and ``min_length``.
If provided, these arguments ensure that the string is at most or at least the
@@ -1525,7 +1537,7 @@
subject = forms.CharField(max_length=100)
message = forms.CharField()
senders = MultiEmailField()
- cc_myself = forms.BooleanField()
+ cc_myself = forms.BooleanField(required=False)
Widgets
=======
@@ -2050,7 +2062,7 @@
subject = models.CharField(max_length=100)
message = models.TextField()
sender = models.EmailField()
- cc_myself = models.BooleanField()
+ cc_myself = models.BooleanField(required=False)
You could use this model to create a form (using ``form_for_model()``). You
could also use existing ``Message`` instances to create a form for editing
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---