mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Refs #32819 -- Added id to ErrorList class and template.
This commit is contained in:
@@ -1025,13 +1025,17 @@ method you're using:
|
||||
Customizing the error list format
|
||||
---------------------------------
|
||||
|
||||
.. class:: ErrorList(initlist=None, error_class=None, renderer=None)
|
||||
.. class:: ErrorList(initlist=None, error_class=None, renderer=None, field_id=None)
|
||||
|
||||
By default, forms use ``django.forms.utils.ErrorList`` to format validation
|
||||
errors. ``ErrorList`` is a list like object where ``initlist`` is the
|
||||
list of errors. In addition this class has the following attributes and
|
||||
methods.
|
||||
|
||||
.. versionchanged:: 5.2
|
||||
|
||||
The ``field_id`` argument was added.
|
||||
|
||||
.. attribute:: error_class
|
||||
|
||||
The CSS classes to be used when rendering the error list. Any provided
|
||||
@@ -1043,6 +1047,16 @@ Customizing the error list format
|
||||
Defaults to ``None`` which means to use the default renderer
|
||||
specified by the :setting:`FORM_RENDERER` setting.
|
||||
|
||||
.. attribute:: field_id
|
||||
|
||||
.. versionadded:: 5.2
|
||||
|
||||
An ``id`` for the field for which the errors relate. This allows an
|
||||
HTML ``id`` attribute to be added in the error template and is useful
|
||||
to associate the errors with the field. The default template uses the
|
||||
format ``id="{{ field_id }}_error"`` and a value is provided by
|
||||
:meth:`.Form.add_error` using the field's :attr:`~.BoundField.auto_id`.
|
||||
|
||||
.. attribute:: template_name
|
||||
|
||||
The name of the template used when calling ``__str__`` or
|
||||
|
||||
@@ -249,6 +249,10 @@ Forms
|
||||
* The new :class:`~django.forms.TelInput` form widget is for entering telephone
|
||||
numbers and renders as ``<input type="tel" ...>``.
|
||||
|
||||
* The new ``field_id`` argument for :class:`~django.forms.ErrorList` allows an
|
||||
HTML ``id`` attribute to be added in the error template. See
|
||||
:attr:`.ErrorList.field_id` for details.
|
||||
|
||||
Generic Views
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user