Ticket #5469: docs_newforms_txt.diff

File docs_newforms_txt.diff, 1.4 KB (added by Nis Jørgensen <nis@…>, 17 years ago)

I merged my own docs from 5145 into the ones in the previous page.

  • docs/newforms.txt

     
    981981    >>> f.errors
    982982    {'url': [u'This field is required.'], 'name': [u'This field is required.']}
    983983
     984
    984985``widget``
    985986~~~~~~~~~~
    986987
     
    10521053displayed for unbound forms, and they're not used as fallback values if a
    10531054particular value isn't provided.
    10541055
     1056Note that ``initial`` values are *not* cleaned. It is supposed that values are right, unlike ``data`` values::
     1057
     1058    >>> class NewsForm(forms.Form):
     1059    ...     date = forms.DateField()
     1060    ...     title = forms.CharField()
     1061    >>> f = NewsForm(initial={'date': 'not_a_date'})
     1062    >>> f.as_table()
     1063    <tr><th><label for="id_date">Date:</label></th><td><input type="text" name="date" value="not_a_date" id="id_date" /></td></tr>
     1064    <tr><th><label for="id_title">Title:</label></th><td><input type="text" name="title" id="id_title" /></td></tr>
     1065
     1066This also means that for a ``MultiValueField``, you need to pass in the data as one value, not as the individual subfields.
     1067
    10551068Finally, note that if a ``Field`` defines ``initial`` *and* you include
    10561069``initial`` when instantiating the ``Form``, then the latter ``initial`` will
    10571070have precedence. In this example, ``initial`` is provided both at the field
Back to Top