From 7ac8380799eedb374621317b62ccf026d86ea245 Mon Sep 17 00:00:00 2001 From: Loic Bistuer Date: Sun, 23 Mar 2014 01:08:04 +0700 Subject: Fixed #22318 -- Added Form.has_error() to easily check if a given error has happened. --- docs/ref/forms/api.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'docs/ref/forms') diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index c4d0b18b0f..cb6cf7a51b 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -182,6 +182,17 @@ when defining form errors. Note that ``Form.add_error()`` automatically removes the relevant field from ``cleaned_data``. +.. method:: Form.has_error(field, code=None) + +.. versionadded:: 1.8 + +This method returns a boolean designating whether a field has an error with +a specific error ``code``. If ``code`` is ``None``, it will return ``True`` +if the field contains any errors at all. + +To check for non-field errors use +:data:`~django.core.exceptions.NON_FIELD_ERRORS` as the ``field`` parameter. + Behavior of unbound forms ~~~~~~~~~~~~~~~~~~~~~~~~~ -- cgit v1.3