diff options
| author | Loic Bistuer <loic.bistuer@sixmedia.com> | 2013-11-30 02:38:13 +0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-12-16 16:33:28 -0500 |
| commit | 3ce9829b615336b0f3ac39b080c27fc8cf5af483 (patch) | |
| tree | def5d16f59f583bb20faf530b24e3f3d977fd458 /docs | |
| parent | e2f142030b81a37e1c3187f5d336dcb6014fd1c0 (diff) | |
Fixed #17413 -- Serialization of form errors along with all metadata.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/forms/api.txt | 21 | ||||
| -rw-r--r-- | docs/releases/1.7.txt | 6 |
2 files changed, 27 insertions, 0 deletions
diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index 69667643b4..ef4da9479e 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -117,6 +117,27 @@ The validation routines will only get called once, regardless of how many times you access :attr:`~Form.errors` or call :meth:`~Form.is_valid`. This means that if validation has side effects, those side effects will only be triggered once. +.. method:: Form.errors.as_data() + +.. versionadded:: 1.7 + +Returns a ``dict`` that maps fields to their original ``ValidationError`` +instances. + + >>> f.errors.as_data() + {'sender': [ValidationError(['Enter a valid email address.'])], + 'subject': [ValidationError(['This field is required.'])]} + +.. method:: Form.errors.as_json() + +.. versionadded:: 1.7 + +Returns the errors serialized as JSON. + + >>> f.errors.as_json() + {"sender": [{"message": "Enter a valid email address.", "code": "invalid"}], + "subject": [{"message": "This field is required.", "code": "required"}]} + .. method:: Form.add_error(field, error) .. versionadded:: 1.7 diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt index c0be6860ac..e4ede9913e 100644 --- a/docs/releases/1.7.txt +++ b/docs/releases/1.7.txt @@ -353,6 +353,12 @@ Forms * The new :meth:`~django.forms.Form.add_error()` method allows adding errors to specific form fields. +* The dict-like attribute :attr:`~django.forms.Form.errors` now has two new + methods :meth:`~django.forms.Form.errors.as_data()` and + :meth:`~django.forms.Form.errors.as_json()`. The former returns a ``dict`` + that maps fields to their original errors, complete with all metadata + (error code and params), the latter returns the errors serialized as json. + Internationalization ^^^^^^^^^^^^^^^^^^^^ |
