You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When working with a dynamic add/delete OneToMany collection on the frontend, I take the approach of incrementing a unique index value to replace the prototype.vars.name string. As opposed to trying to ensure a 0, 1, 2, 3, etc. order which can be a pain, especially with nested collections.
The user may submit things in an order like 1, 3, 4, 7, etc. depending how they added/removed things. This works if there are no form errors.
The bug happens when the form errors kick in. If the user submits collection children with indices 1, 3, 4, 7, they render fine with said indices, but the errors are trying to map to 1, 2, 3, 4, etc. It seems like the errors get the first index and just start incrementing by 1 instead of using the actual indices.
How to reproduce
The following code is a trimmed down and renamed version of my code, so no promises that the following 100% works.
Uh oh!
There was an error while loading. Please reload this page.
Symfony version(s) affected
6.4
Description
When working with a dynamic add/delete OneToMany collection on the frontend, I take the approach of incrementing a unique index value to replace the
prototype.vars.name
string. As opposed to trying to ensure a 0, 1, 2, 3, etc. order which can be a pain, especially with nested collections.The user may submit things in an order like 1, 3, 4, 7, etc. depending how they added/removed things. This works if there are no form errors.
The bug happens when the form errors kick in. If the user submits collection children with indices 1, 3, 4, 7, they render fine with said indices, but the errors are trying to map to 1, 2, 3, 4, etc. It seems like the errors get the first index and just start incrementing by 1 instead of using the actual indices.
How to reproduce
The following code is a trimmed down and renamed version of my code, so no promises that the following 100% works.
Parent entity:
Child entity:
Parent form:
Child form:
Main form template:
Collection helper template:
In the controller, I'm not doing anything out of the ordinary:
Possible Solution
If possible, the form errors should not increment based on the first index but follow the indices of the actual form elements.
Additional Context
This is from the debugger category for Forms. You can see the Forms are indexed 1, 3, 4, 7.
This is from the debugger category for Validator. You can see it is trying to map errors to 1, 2, 3, 4.
What happens is the form renders:
{{ form_errors(collection) }}
The text was updated successfully, but these errors were encountered: