summaryrefslogtreecommitdiff
path: root/django/forms/forms.py
diff options
context:
space:
mode:
authorLoic Bistuer <loic.bistuer@gmail.com>2014-03-23 01:08:04 +0700
committerTim Graham <timograham@gmail.com>2014-03-24 07:21:32 -0400
commit7ac8380799eedb374621317b62ccf026d86ea245 (patch)
tree45f289c8ed60df14ce6ca2312f6ad5232b85480e /django/forms/forms.py
parent3f7615cddc69235d466fb680fb05869f2a80d1e4 (diff)
Fixed #22318 -- Added Form.has_error() to easily check if a given error has happened.
Diffstat (limited to 'django/forms/forms.py')
-rw-r--r--django/forms/forms.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py
index da30a6220a..97a344e9fc 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -334,6 +334,15 @@ class BaseForm(object):
if field in self.cleaned_data:
del self.cleaned_data[field]
+ def has_error(self, field, code=None):
+ if code is None:
+ return field in self.errors
+ if field in self.errors:
+ for error in self.errors.as_data()[field]:
+ if error.code == code:
+ return True
+ return False
+
def full_clean(self):
"""
Cleans all of self.data and populates self._errors and