Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fc22dfe

Browse filesBrowse files
author
Cristoforo Cervino
committed
add form_attr option doc
1 parent d5173b0 commit fc22dfe
Copy full SHA for fc22dfe

File tree

2 files changed

+29
-0
lines changed
Filter options

2 files changed

+29
-0
lines changed

‎reference/forms/types/form.rst

Copy file name to clipboardExpand all lines: reference/forms/types/form.rst
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ on all types for which ``FormType`` is the parent.
1919
| | - `error_bubbling`_ |
2020
| | - `error_mapping`_ |
2121
| | - `extra_fields_message`_ |
22+
| | - `form_attr`_ |
2223
| | - `help`_ |
2324
| | - `help_attr`_ |
2425
| | - `help_html`_ |
@@ -116,6 +117,8 @@ The actual default value of this option depends on other field options:
116117

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

120+
.. include:: /reference/forms/types/options/form_attr.rst.inc
121+
119122
.. include:: /reference/forms/types/options/help.rst.inc
120123

121124
.. include:: /reference/forms/types/options/help_attr.rst.inc
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
``form_attr``
2+
~~~~~~~~~~~~~
3+
4+
**type**: ``bool`` or ``string`` **default**: ``false``
5+
6+
When ``true`` and used on a form element, it adds a `"form" attribute`_. to its HTML field representation with
7+
its HTML form id. By doing this, form element can be rendered outside HTML form while still working as expected::
8+
9+
$builder->add('body', TextareaType::class, [
10+
'form_attr' => true,
11+
]);
12+
13+
This can be useful when you need to solve nested form problems.
14+
You can also set this to ``true`` on a root form to automatically set the "form" attribute on all its children.
15+
16+
.. note::
17+
18+
When root form has no ID, ``form_attr`` required to be a string identifier to be used as form ID.
19+
20+
.. caution::
21+
22+
HTML "form" attribute was introduced to let you explicitly bind a control with a form even if it is
23+
not nested inside it. Don't forget to check for `browser compatibility`_.
24+
25+
.. _`"form" attribute`: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fae-form
26+
.. _`browser compatibility`: https://caniuse.com/form-attribute

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.