-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Validator] Insufficient documentation or bugs #10992
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
Hello @crtl, sorry for the late response. In fact your example in not exactly the same but quite similar to the one of your first link. $constraints = new Assert\Collection([
"fields" => [
"type" => new Assert\Required([
"constraints" => [
new Assert\Choice([
"choices" => ["credentials", "google"],
"groups" => ["type"]
]),
],
"groups" => ["type", "google"],
]),
"token" => new Assert\Required([
"constraints" => [
new Assert\NotBlank([
"groups" => ["google"],
],
],
"groups" => ["type", "google"],
]),
],
// the collection constraint must be traversed for each nested group
"groups" => ["type", "google"],
"allowMissingFields" => false,
]); So each field is required in all groups by default, you need to change this one line in your example to get the intended behavior: -"token" => new Assert\NotBlank([
+"token" => new Assert\Optional(new Assert\NotBlank([
"groups" => ["google"]
-])
+])) @symfony/team-symfony-docs do you think we need a PR for this? Thanks! |
I want really aware of this Required and Optional stuff. I DO think we should document this better :) |
Thanks for the input @weaverryan, then I suggest to update this article https://symfony.com/doc/current/validation/raw_values.html to add a new section with groups, to tell about what I've explained in my comment above. WDYT? |
That looks right. But we should also link to that (if we don’t already) from the CollectionType |
I guess you're thinking about the |
In fact it fitted more smoothly in the |
I wanted to use the validator component but I am having some problems and many of them are related to insufficient docs.
Either im to dumb, the docs are incomplete, theres a bug or all of the three.
Given the following example:
The Resulting messages are:
According to the documentation:
Only the group
type
should be validated.If I pass a sequence of
["type", "google"]
it validates thetype
group first and then validatesgoogle
group, but shows all fields fromtype
group as unexpected fields.Aside of that, all examples are given for object validation.
Its the total opposite in my opinion, in most cases you will get input as an scalar, array or object and not a Class.
The text was updated successfully, but these errors were encountered: