Skip to content

[Form] "form_attr" FormType option documentation #15108

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
Apr 8, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions reference/forms/types/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on all types for which ``FormType`` is the parent.
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `extra_fields_message`_ |
| | - `form_attr`_ |
| | - `help`_ |
| | - `help_attr`_ |
| | - `help_html`_ |
Expand Down Expand Up @@ -116,6 +117,8 @@ The actual default value of this option depends on other field options:

.. include:: /reference/forms/types/options/extra_fields_message.rst.inc

.. include:: /reference/forms/types/options/form_attr.rst.inc

.. include:: /reference/forms/types/options/help.rst.inc

.. include:: /reference/forms/types/options/help_attr.rst.inc
Expand Down
20 changes: 20 additions & 0 deletions reference/forms/types/options/form_attr.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
``form_attr``
~~~~~~~~~~~~~

**type**: ``boolean`` or ``string`` **default**: ``false``

When ``true`` and used on a form element, it adds a `"form" attribute`_ to its HTML field representation with
its HTML form id. By doing this, a form element can be rendered outside the HTML form while still working as expected::

$builder->add('body', TextareaType::class, [
'form_attr' => true,
]);

This can be useful when you need to solve nested form problems.
You can also set this to ``true`` on a root form to automatically set the "form" attribute on all its children.

.. note::

When the root form has no ID, ``form_attr`` is required to be a string identifier to be used as the form ID.

.. _`"form" attribute`: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fae-form