mirror of
https://github.com/django/django.git
synced 2025-10-28 16:16:12 +00:00
Fixed #11776 -- Added CSS class for non-field/top of form errors.
Thanks Daniel Pope for the suggestion.
This commit is contained in:
@@ -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))
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user