mirror of https://github.com/django/django.git
Forms docs: More emphasis in 'id' value customizability.
This commit is contained in:
parent
21c2bfdff3
commit
18ea1c473b
|
@ -408,21 +408,27 @@ classes, as needed. The HTML will look something like::
|
||||||
|
|
||||||
.. _ref-forms-api-configuring-label:
|
.. _ref-forms-api-configuring-label:
|
||||||
|
|
||||||
Configuring HTML ``<label>`` tags
|
Configuring form elements' HTML ``id`` attributes and ``<label>`` tags
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
An HTML ``<label>`` tag designates which label text is associated with which
|
.. attribute:: Form.auto_id
|
||||||
form element. This small enhancement makes forms more usable and more accessible
|
|
||||||
to assistive devices. It's always a good idea to use ``<label>`` tags.
|
|
||||||
|
|
||||||
By default, the form rendering methods include HTML ``id`` attributes on the
|
By default, the form rendering methods include:
|
||||||
form elements and corresponding ``<label>`` tags around the labels. The ``id``
|
|
||||||
attribute values are generated by prepending ``id_`` to the form field names.
|
|
||||||
This behavior is configurable, though, if you want to change the ``id``
|
|
||||||
convention or remove HTML ``id`` attributes and ``<label>`` tags entirely.
|
|
||||||
|
|
||||||
Use the ``auto_id`` argument to the ``Form`` constructor to control the label
|
* HTML ``id`` attributes on the form elements.
|
||||||
and ``id`` behavior. This argument must be ``True``, ``False`` or a string.
|
|
||||||
|
* The corresponding ``<label>`` tags around the labels. An HTML ``<label>`` tag
|
||||||
|
designates which label text is associated with which form element. This small
|
||||||
|
enhancement makes forms more usable and more accessible to assistive devices.
|
||||||
|
It's always a good idea to use ``<label>`` tags.
|
||||||
|
|
||||||
|
The ``id`` attribute values are generated by prepending ``id_`` to the form
|
||||||
|
field names. This behavior is configurable, though, if you want to change the
|
||||||
|
``id`` convention or remove HTML ``id`` attributes and ``<label>`` tags
|
||||||
|
entirely.
|
||||||
|
|
||||||
|
Use the ``auto_id`` argument to the ``Form`` constructor to control the ``id``
|
||||||
|
and label behavior. This argument must be ``True``, ``False`` or a string.
|
||||||
|
|
||||||
If ``auto_id`` is ``False``, then the form output will not include ``<label>``
|
If ``auto_id`` is ``False``, then the form output will not include ``<label>``
|
||||||
tags nor ``id`` attributes::
|
tags nor ``id`` attributes::
|
||||||
|
@ -503,7 +509,7 @@ appended after any label name when a form is rendered.
|
||||||
The default ``label_suffix`` is translatable.
|
The default ``label_suffix`` is translatable.
|
||||||
|
|
||||||
It's possible to customize that character, or omit it entirely, using the
|
It's possible to customize that character, or omit it entirely, using the
|
||||||
``label_suffix`` parameter::
|
``label_suffix`` parameter::
|
||||||
|
|
||||||
>>> f = ContactForm(auto_id='id_for_%s', label_suffix='')
|
>>> f = ContactForm(auto_id='id_for_%s', label_suffix='')
|
||||||
>>> print(f.as_ul())
|
>>> print(f.as_ul())
|
||||||
|
|
Loading…
Reference in New Issue