Skip to content

Update bootstrap4.rst #13650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions form/bootstrap4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ If you prefer to apply the Bootstrap styles on a form to form basis, include the
{{ form(form) }}
{% endblock %}

Error Messages
--------------

Form errors are rendered **inside** the ``<label>`` element to make sure there
is a strong connection between the error and its ``<input>``, as required by the
`WCAG 2.0 standard`_. To achieve this, ``form_errors()`` is called by
``form_label()`` internally. So you shouldn't use ``form_errors()`` at all; if you
do, you'll get the error messages displayed *twice*.

Checkboxes and Radios
---------------------

For a checkbox/radio field, calling ``form_label()`` doesn't render anything. Due to
Bootstrap internals, the label is already rendered by ``form_widget()``.

Accessibility
-------------

Expand All @@ -100,16 +115,5 @@ and ``checkbox-custom`` respectively.
{{ form_row(form.myRadio, {label_attr: {class: 'radio-custom'} }) }}
{{ form_row(form.myCheckbox, {label_attr: {class: 'checkbox-custom'} }) }}

Labels and Errors
-----------------

When you use the Bootstrap form themes and render the fields manually, calling
``form_label()`` for a checkbox/radio field doesn't render anything. Due to Bootstrap
internals, the label is already rendered by ``form_widget()``.

Form errors are rendered **inside** the ``<label>`` element to make sure there
is a strong connection between the error and its ``<input>``, as required by the
`WCAG 2.0 standard`_.

.. _`WCAG 2.0 standard`: https://www.w3.org/TR/WCAG20/
.. _`custom forms`: https://getbootstrap.com/docs/4.4/components/forms/#custom-forms