-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Add @Validate constraint #17622
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
I wonder why the decision was made to not bother cascading everything by default. When I want my form to be valid, what possible use case would be that I could want my embedded form to be ignored? This default behavior is weird to me and I'd expect embedded forms to always be validated unless told otherwise with active validation groups being respected. This confusion is causing a lot of bugs in a lot of code. The current shape leads to a lot of extra work to get embedded forms properly validated when using conditional validation. |
I would assume one reason is that it now forces you to define the validation properly in the entity which makes sense as you might need validation in different contexts. With a slightly different intent I proposed #16984 which lacks feedback so far. |
While this proposal may postively influence problems when using validation in conjunction with forms, the original problem is more about isolation of validation metadata of shared code (like a reuseable address class, that defines various validation groups, to validate the address under certain aspects like completeness or validity of single values). |
Why is this needed? I see a solution but don't understand the problem. |
Ok, I try to present a (legit) use-case:
When i now validate a user in the |
Thanks for the explanation! I think this could be solved by adding support for the |
I dont think, groups on Valid would solve all cases. Another benefit of my proposal is the isolation of groups names to code directly interacting with the (sub-)validated entity. |
I warmly welcome everyone of you to take a look at the implementation in #21111 and see if it solves your issues. |
… (xabbuh) This PR was merged into the 3.4 branch. Discussion ---------- [Validator] add groups support to the Valid constraint | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #3622, #17622 | License | MIT | Doc PR | TODO Commits ------- 0ca27cc add groups support to the Valid constraint
To solve problems like #3622 I propose adding a new constraint named
Validate
. The parameters of this constraint aregroups
andforeignGroups
.The constraint validator of
Validate
starts a new subvalidation in the same context as the original validation, but usesforeignGroups
:The text was updated successfully, but these errors were encountered: