-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] property path for violations is incorrect #3995
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
When the DelegatingValidationListener is refactored (see #3903), this can be implemented. What you want is basically a custom mapping function that maps the property paths data[0] to the forms children[Mon].children[0] A second solution for your problem is to make the forms Mon, Tue etc. virtual. Virtual forms are used for presentation only and are not mapped directly to the domain model, resulting in the mapping: data[0] <-> children[Mon].children[0] To do this, you would have to move your value transformer logic to a form listener that rebuilds the form every time your data is set. |
Thanks for your explanation. For now I'll keep it as-is and wait for #3903 to be resolved. The form between the base and the entity forms also contain quite some logic which would probably result in a lot of refactoring and possibly unclean code. I'll resort to the virtual solution if I'll find myself running out of time before the issue is resolved |
Can you please verify if this is fixed by #4341? |
@bschussek it appears the bug still exists. The error is still mapped to "data[2].break" rather than "data[Wed][0].break" (or something similar) Anything I can do to help you debug? |
I think that the mapping function I described above is not really feasible. I rather think now that your use case is exactly the use case of virtual forms. Could you test whether virtual forms fix your problem? |
@bschussek When the deadline approached a while ago, I implemented the work-a-round you provided around a month ago, and this indeed worked fine. Does this mean that the way the form was before, is actually not intended use? |
Yes, forms are not intended to be used like that. A form that does not map to a property of the underlying data should either be unmapped ("property_path" => false, or "mapped" => false as of #4341) or virtual ("virtual" => true). |
See also symfony/symfony-docs#1387 |
I have the following situation:
There is a form which shows a list of entities of some kind, kind of similar to a collection form. However, the entities need to be shown in some kind of hierarchy, so even though the app Data is a plain array, the clientData and form it self are built in the following way:
etc...
The transformation between the two is done using a DataTransformer on the topmost form: https://gist.github.com/2419554
The form works fine except for validation, for some reason all errors bubble up all the way to the top form, even if they should display on the bottom forms (form.Mon.0, form.Mon.1, etc). While trying to find out what was wrong, I came to the conclusion that the property path of the violations was incorrect, or at least not conform to the way the form was build up:
data[0].field
data[0].field2
data[1].field
rather than
data[Mon][0].field
data[Mon][0].field2
data[Mon][1].field
This causes them to bubble all the way up, as they cannot be mapped to the form.
The text was updated successfully, but these errors were encountered: