-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Render same field multiple times #26531
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
Comments
Question for Form experts: is this limitation just to allow |
There is the limitation of ids that are supposed to stay unique in the page, this could lead to labels not being correctly linked to their inputs. |
By adding another submit button with different name and same label shouldn't be enough to cover the use case? |
Yes, that's what I ultimately did. Not a fan of duplications tho. |
A workaround for this is to set a var: {% set saveBtn = form_row(form.save) %} and rendering it twice (or as much as you need). |
If you want to render the same form multiple times, you can use named forms for this afaik. Your screenshot is too small to clearly see how or what. |
You'll duplicate the id everytime you re-use the form field. |
Symfony best practice: |
Ok plenty things have been answered and even some good workarounds given. I am going to ask different question now. What's the reason for returning empty string for fields which were already rendered, if user tries to render them multiple times, instead of throwing exception with explanation? How about deprecating this silent behaviour? |
@ostrolucky: It would make sense to me, indeed. |
See #26531 If we disallow calling this for same field twice, we are opening up opportunity to change this behaviour in future. E.g. in Symfony 6 we can make it no longer throw exception and allow to render same field more times, while shifting responsibility of making sure IDs do not collide to user, or even generate different IDs for subsequent fields. Currently this can't be changed due to BC. |
…y string (ostrolucky) This PR was squashed before being merged into the 4.2-dev branch (closes #27247). Discussion ---------- [Form] Deprecate `searchAndRenderBlock` returning empty string | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #26531 | License | MIT | Doc PR | - I would like to remove this silent behavior, because it's confusing Commits ------- 02f2f0e [Form] Deprecate `searchAndRenderBlock` returning empty string
This is a common problem. Only workarounds exists is not using form_* functions for subsequent fields.
Wanted to solve this by doing
quickly found setRendered does not accept arguments and PRs for multiple different use cases has been rejected1 in2 past3. Is this use case good enough for this change now?
This is specifically very useful to split form visually to two, where one block is just for RepeatedType and SubmitType. Here was the requirement from our designer
If I could render same field twice, I could reuse same button field and be done with it.
The text was updated successfully, but these errors were encountered: