Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] Getting FormErrors indexed by validation-group ? #5050

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
alterphp opened this issue Jul 25, 2012 · 5 comments
Closed

[Form] Getting FormErrors indexed by validation-group ? #5050

alterphp opened this issue Jul 25, 2012 · 5 comments

Comments

@alterphp
Copy link

I use validation-groups on multi-tabbed form and I'd like to know the first failed tabbed part into directly display the corresponding tab. To do that, I need to know for each validation group if it's validated or not. How is it possible to implement this feature in Symfony, and feasable with the new 2.1 architecture ?

@webmozart
Copy link
Contributor

Partial copy of my reply from StackOverflow:

Unfortunately this is currently not possible without hacking the core. The problem is that Form contains a references to FormError objects, which do not keep references to the original ConstraintViolation objects, which also do not keep references of the group under which the violation occurred.

Even if we added this feature, the problem would remain that a constraint is only evaluated once if it belongs to multiple groups that are validated at once. The violation would then only store the first group, even though it would have failed in the other groups too.

@alterphp
Copy link
Author

If the binding process loops on every constraints of each validation-group (but validate them only if not done yet), it must be possible to keep tracks on every failled constraint in each group ?

Can we state that, if a validation constraint fails in a validation group, it will fail for other group it's in ?

@webmozart
Copy link
Contributor

If the binding process loops on every constraints of each validation-group (but validate them only if not done yet), it must be possible to keep tracks on every failled constraint in each group ?

Not really, because the validation process does not control and modify the violations added by each validator. What you ask for is to change the violation afterwards to also include the groups that it would have occurred in. I don't like that smell...

Can we state that, if a validation constraint fails in a validation group, it will fail for other group it's in ?

Correct :) (unless you have a custom constraint that does funky stuff based on the current group, which I absolutely discourage)

@stof
Copy link
Member

stof commented Aug 18, 2014

The FormError now has a reference to the ConstraintViolation causing it (through getCause() since 2.5. Once #11657 will be merged in 2.6, the violation will give you access to the Constraint itself. So doing such grouping of errors will become possible in 2.6 (by getting all form errors, which is already possible in 2.5, and grouping them in userland)

@webmozart
Copy link
Contributor

@stof Correct.

webmozart added a commit that referenced this issue Aug 19, 2014
… (webmozart)

This PR was merged into the 2.6-dev branch.

Discussion
----------

[Validator] Added ConstraintViolation::getConstraint()

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #5050
| License       | MIT
| Doc PR        | -

This PR adds a `getConstraint()` method to the `ConstraintViolation` in order to access the constraint causing the violation.

Related to #7276, #7273 and #9691.

Commits
-------

ce1d209 [Validator] Added ConstraintViolation::getConstraint()
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

3 participants