diff options
| author | Baptiste Mispelon <bmispelon@gmail.com> | 2013-11-12 20:27:21 +0100 |
|---|---|---|
| committer | Baptiste Mispelon <bmispelon@gmail.com> | 2013-11-12 21:05:06 +0100 |
| commit | 8d1f3396679c8bb446ad43b0727b45bdb77d87b4 (patch) | |
| tree | cf0e3982b6d9b4ebb1c8a220c750e1a1bdec12c7 /docs/ref | |
| parent | 12ff1623d63046b9e27f7f8b9fe20750106889ca (diff) | |
[1.5.x] Removed a mention of `Form._errors` from the documentation.
Also removed a sentence that was incorrect: raising a
`ValidationError` inside `Form.clean` doesn't clear the
`cleaned_data` attribute.
Thanks to loic84 and timograham for the review.
Backport of 9aa6d4bdb6618ba4f17acc7b7c0d1462d6cbc718 and
0048ed77c7016a03aed6dbc255a6372f3df2ccd5 from master.
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/forms/validation.txt | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/docs/ref/forms/validation.txt b/docs/ref/forms/validation.txt index e97f645384..392ee226a8 100644 --- a/docs/ref/forms/validation.txt +++ b/docs/ref/forms/validation.txt @@ -82,6 +82,10 @@ overridden: cleaned data if you override this method (by default, ``Form.clean()`` just returns ``self.cleaned_data``). + Since the field validation method have been run by the time ``clean()`` is + called, you also have access to the form's ``errors`` attribute which + contains all the errors raised by previous steps. + Note that any errors raised by your ``Form.clean()`` override will not be associated with any field in particular. They go into a special "field" (called ``__all__``), which you can access via the @@ -98,7 +102,8 @@ These methods are run in the order given above, one field at a time. That is, for each field in the form (in the order they are declared in the form definition), the ``Field.clean()`` method (or its override) is run, then ``clean_<fieldname>()``. Finally, once those two methods are run for every -field, the ``Form.clean()`` method, or its override, is executed. +field, the ``Form.clean()`` method, or its override, is executed, no matter if +the previous methods have raised errors or not. Examples of each of these methods are provided below. @@ -107,15 +112,6 @@ field, if the ``Field.clean()`` method raises a ``ValidationError``, any field-specific cleaning method is not called. However, the cleaning methods for all remaining fields are still executed. -The ``clean()`` method for the ``Form`` class or subclass is always run. If -that method raises a ``ValidationError``, ``cleaned_data`` will be an empty -dictionary. - -The previous paragraph means that if you are overriding ``Form.clean()``, you -should iterate through ``self.cleaned_data.items()``, possibly considering the -``_errors`` dictionary attribute on the form as well. In this way, you will -already know which fields have passed their individual validation requirements. - .. _described later: Form subclasses and modifying field errors |
