diff options
author | Nick Presta <nick@nickpresta.ca> | 2014-04-14 23:58:51 -0400 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2014-06-02 15:22:15 -0400 |
commit | 11f0899bbe7c04dc6109f57c3b36ed8621b8f08e (patch) | |
tree | 92bbc93a67159d5c418ae128598de4b6db326b52 /django/forms/utils.py | |
parent | a00efa30d6e5ca220b914415904fff5fa0a6f2c5 (diff) | |
download | django-11f0899bbe7c04dc6109f57c3b36ed8621b8f08e.tar.gz |
Fixed #11776 -- Added CSS class for non-field/top of form errors.
Thanks Daniel Pope for the suggestion.
Diffstat (limited to 'django/forms/utils.py')
-rw-r--r-- | django/forms/utils.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/django/forms/utils.py b/django/forms/utils.py index f7f53e9a0a..14253f36fe 100644 --- a/django/forms/utils.py +++ b/django/forms/utils.py @@ -80,6 +80,14 @@ class ErrorList(UserList, list): """ A collection of errors that knows how to display itself in various formats. """ + def __init__(self, initlist=None, error_class=None): + super(ErrorList, self).__init__(initlist) + + if error_class is None: + self.error_class = 'errorlist' + else: + self.error_class = 'errorlist {}'.format(error_class) + def as_data(self): return ValidationError(self.data).error_list @@ -99,8 +107,10 @@ class ErrorList(UserList, list): def as_ul(self): if not self.data: return '' + return format_html( - '<ul class="errorlist">{0}</ul>', + '<ul class="{0}">{1}</ul>', + self.error_class, format_html_join('', '<li>{0}</li>', ((force_text(e),) for e in self)) ) |