8000 [Form] Fixed the validation of form validation constraints by stof · Pull Request #4625 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Fixed the validation of form validation constraints #4625

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
wants to merge 1 commit into from

Conversation

stof
Copy link
Member
@stof stof commented Jun 20, 2012

Validating the form constraints for each validation group results in
duplicated errors when several validation groups are used.

This is an attempt to fix #4427.

@bschussek can you look at it ? I'm not sure if it is the right way to fix it.

Looking at the code of the GraphWalker to debug this, I think we have an issue in the validator component itself (and the Form constraints being only the easiest way to trigger the issue): if a constraint is attached on an object in 2 validation groups and you use both groups when calling the validator, the ConstraintValidator is called twice. This is not something you will generally do in your constraint mapping, but the FormValidator was working in such a way: form constraints were validated for all validation groups of the form. However, I don't see how the GraphWalker could remember the constraint has already been validated for this instance as walkConstraint does not have access to the object.

Validating the form constraints for each validation group results in
duplicated errors when several validation groups are used.
@travisbot
Copy link

This pull request passes (merged 16eb638 into 55c6df9).

@webmozart
Copy link
Contributor

I don't think that walking the constraints in Default group instead should be the solution. Instead, we should check whether the constraints are member of the validated groups before actually validating them. We could also presort the constraints, like it is done in the GraphWalker.

@stof
Copy link
Member Author
stof commented Jun 27, 2012

@bschussek The constraint added on the Fomr are not member of any group. Previously, it was considering that they are part of all groups, and I changed it so that they are validated only for one group.

@webmozart
Copy link
Contributor

@s 8000 tof They usually are members of group Default, but one could easily add constraints with different groups.

@stof
Copy link
Member Author
stof commented Jul 3, 2012

@bschussek you cannot specify groups for the constraint added in a form. and currently, the code was considering they were in all groups used by the form, thus validating them several times.

@webmozart
Copy link
Contributor

@stof Why couldn't you set groups for them?

'constraints' => new NotBlank(array('groups' => 'MyGroup')),

@stof
Copy link
Member Author
stof commented Jul 4, 2012

@bschussek this would not change anything. Look at the way the FormValidator is using these constraints.

@webmozart
Copy link
Contributor

I know. That's the problem I am talking about :)

Instead, we should check whether the constraints are member of the validated groups before actually validating them. We could also presort the constraints, like it is done in the GraphWalker.

@fabpot
Copy link
Member
fabpot commented Jul 9, 2012

Closing in favor of #4810

@fabpot fabpot closed this Jul 9, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Form] Duplicated errors for constraints when using several validation groups
4 participants
0