summaryrefslogtreecommitdiff
path: root/docs/ref/forms
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-10-21 13:50:48 -0400
committerTim Graham <timograham@gmail.com>2015-10-21 13:53:48 -0400
commit55ed23fd3e17c7743252a967a8f9957e038d35c4 (patch)
treeb6700a2596cdb369eb343eb05c84595521e485b9 /docs/ref/forms
parent5a9e93e05423c176adfef714f804fe80e6fbb522 (diff)
[1.9.x] Fixed #21894 -- Corrected a form.clean() example in case a superclass doesn't return data.
Backport of 80855a4b3787bace050a8b4a2b80f79306e69812 from master
Diffstat (limited to 'docs/ref/forms')
-rw-r--r--docs/ref/forms/validation.txt26
1 files changed, 17 insertions, 9 deletions
diff --git a/docs/ref/forms/validation.txt b/docs/ref/forms/validation.txt
index 5f6db434f8..fc340d3b04 100644
--- a/docs/ref/forms/validation.txt
+++ b/docs/ref/forms/validation.txt
@@ -371,16 +371,24 @@ example::
In this code, if the validation error is raised, the form will display an
error message at the top of the form (normally) describing the problem.
-Note that the call to ``super(ContactForm, self).clean()`` in the example code
-ensures that any validation logic in parent classes is maintained.
+The call to ``super(ContactForm, self).clean()`` in the example code ensures
+that any validation logic in parent classes is maintained. If your form
+inherits another that doesn't return a ``cleaned_data`` dictionary in its
+``clean()`` method (doing so is optional), then don't assign ``cleaned_data``
+to the result of the ``super()`` call and use ``self.cleaned_data`` instead::
-The second approach might involve assigning the error message to one of the
-fields. In this case, let's assign an error message to both the "subject" and
-"cc_myself" rows in the form display. Be careful when doing this in practice,
-since it can lead to confusing form output. We're showing what is possible
-here and leaving it up to you and your designers to work out what works
-effectively in your particular situation. Our new code (replacing the previous
-sample) looks like this::
+ def clean(self):
+ super(ContactForm, self).clean()
+ cc_myself = self.cleaned_data.get("cc_myself")
+ ...
+
+The second approach for reporting validation errors might involve assigning the
+error message to one of the fields. In this case, let's assign an error message
+to both the "subject" and "cc_myself" rows in the form display. Be careful when
+doing this in practice, since it can lead to confusing form output. We're
+showing what is possible here and leaving it up to you and your designers to
+work out what works effectively in your particular situation. Our new code
+(replacing the previous sample) looks like this::
from django import forms