Django

Code

Changeset 6564

Show
Ignore:
Timestamp:
10/20/07 07:21:16 (1 year ago)
Author:
mtredinnick
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/newforms.txt

    r6532 r6564  
    101101        message = forms.CharField() 
    102102        sender = forms.EmailField() 
    103         cc_myself = forms.BooleanField(
     103        cc_myself = forms.BooleanField(required=False
    104104 
    105105A form is composed of ``Field`` objects. In this case, our form has four 
     
    10611061    ...     message = forms.CharField() 
    10621062    ...     sender = forms.EmailField(help_text='A valid e-mail address, please.') 
    1063     ...     cc_myself = forms.BooleanField(
     1063    ...     cc_myself = forms.BooleanField(required=False
    10641064    >>> f = HelpTextContactForm(auto_id=False) 
    10651065    >>> print f.as_table() 
     
    11401140 
    11411141    * Default widget: ``CheckboxInput`` 
    1142     * Empty value: ``None`` 
     1142    * Empty value: ``False`` 
    11431143    * 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`` 
     1149instead 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``. 
    11451156 
    11461157``CharField`` 
     
    11501161    * Empty value: ``''`` (an empty string) 
    11511162    * 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. 
    11531165 
    11541166Has two optional arguments for validation, ``max_length`` and ``min_length``. 
     
    15261538        message = forms.CharField() 
    15271539        senders = MultiEmailField() 
    1528         cc_myself = forms.BooleanField(
     1540        cc_myself = forms.BooleanField(required=False
    15291541 
    15301542Widgets 
     
    20512063        message = models.TextField() 
    20522064        sender = models.EmailField() 
    2053         cc_myself = models.BooleanField(
     2065        cc_myself = models.BooleanField(required=False
    20542066 
    20552067You could use this model to create a form (using ``form_for_model()``). You