Skip to content

[Constraints/Collection] Add missing : and ~ in the yaml code block #8587

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

Merged
merged 1 commit into from
Nov 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions reference/constraints/Collection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ following:
fields:
personal_email: Email
short_bio:
- NotBlank
- NotBlank: ~
- Length:
max: 100
maxMessage: Your short bio is too long!
Expand Down Expand Up @@ -223,7 +223,7 @@ you can do the following:
- Collection:
fields:
personal_email:
- Required
- Required:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this proposal the right fix?

Shouldn't this:

        - Collection:
            fields:
                personal_email:
                    - Required:
                        - NotBlank: ~
                        - Email: ~

be like this instead?

        - Collection:
            fields:
                personal_email:
                    - Required: ~
                    - NotBlank: ~
                    - Email: ~

Copy link
Contributor Author

@NicolasDievart NicolasDievart Nov 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know about "Required" before (always used NotBlank), but I tried

- Required:
    - NotBlank: ~
    - Email: ~

And it works, and I based my guess also on the annotation code block

@Assert\Required({@Assert\NotBlank, @Assert\Email})

Which seems to be, for required, a combination of constraints

But according to this:
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraints/Required.php

Your guess seems correct too, as it can be nested or a side by side constraint

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nesting is correct here. We do specify the constraints that are required for each collection entry.

- NotBlank: ~
- Email: ~
alternate_email:
Expand Down