8000 [Form] [Validator] GraphWalker doesn't validate all groups · Issue #5066 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] [Validator] GraphWalker doesn't validate all groups #5066

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

[Form] [Validator] GraphWalker doesn't validate all groups #5066

ricbra opened this issue Jul 26, 2012 · 5 comments
Labels

Comments

@ricbra
Copy link
Contributor
ricbra commented Jul 26, 2012

I have implemented a GroupSequenceProviderInterface on my entity as described here: #3199

When the getGroupSequence() method returns more then one group and the first group triggers a violation, the second (or later) groups don't get validated anymore. This happens in the GraphWalker:

foreach ($groups as $group) {
    $this->walkObjectForGroup($metadata, $object, $group, $propertyPath, Constraint::DEFAULT_GROUP);

    if (count($this->getViolations()) > 0) {
        break;
    }
}

Is this on purpose? I think it is strange a user gets different error messages depending on the groups he filled out on the form. In my use case the user first receives 4 errors. After fixing the errors and a submit he receives another 2 errors.

@stof
Copy link
Member
stof commented Jul 26, 2012

This is exactly what the GroupSequence is about: validating some groups only if the previous ones passed

@ricbra
Copy link
Contributor Author
ricbra commented Jul 26, 2012

How should one implement conditional validation, without using GroupSequenceProvider? I don't want my user to fill out the form on trial and error. Depending on the data he fills out, I want to completely validate the form.

@stof
Copy link
Member
stof commented Jul 26, 2012

What do you mean by conditional validation ?

@ricbra
Copy link
Contributor Author
ricbra commented Jul 26, 2012

Well, simplified my use case: I have a form with text fields: firstname, lastname, a checkbox for "I want to use a voucher" and another textfield "voucher code".
When the user selects the checkbox I also want "voucher code" as required field. And I want to validate it against some service. Currently I have two groups: Default and Voucher. When he select to use a voucher I add the group Voucher. But this doesn't get validated if he doesn't fill out his first- or lastname.

The real form has a lot more fields and validators, so using the Callback validator is not an option.

@webmozart
Copy link
Contributor

Conditional validation is not built into the core, as there are a lot of possibilities that we cannot cover all. You should use a dynamic validation routine instead, either by defining your own custom constraint, by using the Callback constraint or by constraining a custom validation method with True or False.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
0