-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Add "form_attr" FormType option #40430
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5e12bfc
to
4b03b5d
Compare
Hey! I like what you have done here. Keep up the good work. I think @fancyweb has recently worked with this code. Maybe they can help review this? Cheers! Carsonbot |
nicolas-grekas
approved these changes
Mar 16, 2021
src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php
Outdated
Show resolved
Hide resolved
derrabus
approved these changes
Mar 18, 2021
1f8e882
to
5f913ce
Compare
Thank you @cristoforocervino. |
wouterj
added a commit
to symfony/symfony-docs
that referenced
this pull request
Apr 8, 2021
…toforo Cervino, cristoforocervino) This PR was merged into the 5.3-dev branch. Discussion ---------- [Form] "form_attr" FormType option documentation This is the documentation for [#40430](symfony/symfony#40430) Commits ------- c8deb3d add form_attr option doc
Merged
nicolas-grekas
added a commit
that referenced
this pull request
Dec 28, 2022
…Cat) This PR was merged into the 5.4 branch. Discussion ---------- [Form] Make `ButtonType` handle `form_attr` option | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | Not sure | New feature? | Not sure | Deprecations? | no | Tickets | Fix #48794 | License | MIT | Doc PR | N/A Seems #40430 just forgot about `ButtonType` so I’m basically moving the implementation to `BaseType` and duplicating the tests in `ButtonTypeTest`. Commits ------- 318a9ae [Form] Make `ButtonType` handle `form_attr` option
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is this about
This PR add support for
form
attribute to Symfony Form (browser compatibility).The
form
attribute allows form elements to override their associated form (which is their nearest ancestor form element by default). This is extremely useful to solve nested form problem and allows form children to be rendered outside form tag while still working as expected.New "form_attr" FormType option
form_attr
type:
bool
orstring
default:false
If set to
true
on a root form, addsform
attribute on every children with their root form id.This allows you to render form children outside the form tag and avoid nested form problem in some situations while keeping the form working properly.
If set to
true
on a child, addsform
attribute on it with its root form id.This allows you to render that child outside the form tag and avoid nested form problem in some situations while keeping the form working properly.
If root form has no
id
(this may happen by create an unnamed form), you can set it to astring
identifier to be used atFormView
level to link children and root form anyway.Usage on Root Form Example
Form Type
Enable the feature by setting
form_attr
totrue
on the root form.Twig
The following Twig template works properly even if form children are outside their form tag (browser compatibility).
✅ Every form elements work properly even outside form tag.
Usage on Form Child Example
Enable the feature by setting
form_attr
totrue
on selected child.Twig
The following Twig template works properly even if
form.perPage
is outside form tag (browser compatibility).✅
form.perPage
element work properly even outside form tag.