Skip to content

Symfony forms : validation errors message displayed at a wrong place for snake cased sub-forms #46313

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

Closed
spydemon opened this issue May 10, 2022 · 3 comments

Comments

@spydemon
Copy link

Symfony version(s) affected

6.0.8

Description

This issue was already observed on previous versions of Symfony :

But it's still present on Symfony 6.0.8.

The problem is that the form bundle seems not able to correctly identify sub-forms named with snake case names during its validation process and thus fall back the displaying of their errors message to the root form. If nothing is planned to resolve this issues as it is mentioned in the previous tickets linked above, could we at least throw an error if we are creating sub-forms containing snake case names? A warning will probably save time to a bunch of developers. 😄

How to reproduce

I created a small project that illustrate the issue here.

If you checkout the commit 16a6cc1 the errors are displayed as expected:

swappy-20220510-204438

But if you checkout the commit 49776ba, things goes wrong:

swappy-20220510-203956

Errors corresponding to the billing form are displayed at the wrong place, and several times.

Possible Solution

The \Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapper::mapViolation method seems responsible for defining where violations should be rendered.

The problem is that we are comparing the violation property path that is generated from the property attribute name and from the class name of the entity that should be checked by the validation (eg: data.billingAddress.streetNumber in the example coming from my repository) with the name of the sub-form (eg: billing_address.streetNumber in my example) in the \Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapper::matchChild method. A solution could thus be to also check snake case variants of each name present in the violation path, but I'm not sure that such a naive fix won't add regressions somewhere else. 🤔

Additional Context

No response

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants