summaryrefslogtreecommitdiff
path: root/docs/ref/forms
diff options
context:
space:
mode:
Diffstat (limited to 'docs/ref/forms')
-rw-r--r--docs/ref/forms/api.txt21
-rw-r--r--docs/ref/forms/validation.txt10
2 files changed, 18 insertions, 13 deletions
diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt
index 50488b026a..777d73e015 100644
--- a/docs/ref/forms/api.txt
+++ b/docs/ref/forms/api.txt
@@ -199,8 +199,8 @@ Note that any text-based field -- such as ``CharField`` or ``EmailField`` --
always cleans the input into a Unicode string. We'll cover the encoding
implications later in this document.
-If your data does *not* validate, your ``Form`` instance will not have a
-``cleaned_data`` attribute::
+If your data does *not* validate, the ``cleaned_data`` dictionary contains
+only the valid fields::
>>> data = {'subject': '',
... 'message': 'Hi there',
@@ -210,9 +210,12 @@ If your data does *not* validate, your ``Form`` instance will not have a
>>> f.is_valid()
False
>>> f.cleaned_data
- Traceback (most recent call last):
- ...
- AttributeError: 'ContactForm' object has no attribute 'cleaned_data'
+ {'cc_myself': True, 'message': u'Hi there'}
+
+.. versionchanged:: 1.5
+
+Until Django 1.5, the ``cleaned_data`` attribute wasn't defined at all when
+the ``Form`` didn't validate.
``cleaned_data`` will always *only* contain a key for fields defined in the
``Form``, even if you pass extra data when you define the ``Form``. In this
@@ -232,9 +235,9 @@ but ``cleaned_data`` contains only the form's fields::
>>> f.cleaned_data # Doesn't contain extra_field_1, etc.
{'cc_myself': True, 'message': u'Hi there', 'sender': u'foo@example.com', 'subject': u'hello'}
-``cleaned_data`` will include a key and value for *all* fields defined in the
-``Form``, even if the data didn't include a value for fields that are not
-required. In this example, the data dictionary doesn't include a value for the
+When the ``Form`` is valid, ``cleaned_data`` will include a key and value for
+*all* its fields, even if the data didn't include a value for some optional
+fields. In this example, the data dictionary doesn't include a value for the
``nick_name`` field, but ``cleaned_data`` includes it, with an empty value::
>>> class OptionalPersonForm(Form):
@@ -583,7 +586,7 @@ lazy developers -- they're not the only way a form object can be displayed.
Used to display HTML or access attributes for a single field of a
:class:`Form` instance.
-
+
The :meth:`__unicode__` and :meth:`__str__` methods of this object displays
the HTML for this field.
diff --git a/docs/ref/forms/validation.txt b/docs/ref/forms/validation.txt
index 97883d7880..95424d0cd0 100644
--- a/docs/ref/forms/validation.txt
+++ b/docs/ref/forms/validation.txt
@@ -362,7 +362,9 @@ Secondly, once we have decided that the combined data in the two fields we are
considering aren't valid, we must remember to remove them from the
``cleaned_data``.
-In fact, Django will currently completely wipe out the ``cleaned_data``
-dictionary if there are any errors in the form. However, this behavior may
-change in the future, so it's not a bad idea to clean up after yourself in the
-first place.
+.. versionchanged:: 1.5
+
+Django used to remove the ``cleaned_data`` attribute entirely if there were
+any errors in the form. Since version 1.5, ``cleaned_data`` is present even if
+the form doesn't validate, but it contains only field values that did
+validate.