8000 [Validation][RFC] Allow to mix group sequence and validation group · Issue #7204 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validation][RFC] Allow to mix group sequence and validation group #7204

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
lyrixx opened this issue Feb 27, 2013 · 10 comments
Closed

[Validation][RFC] Allow to mix group sequence and validation group #7204

lyrixx opened this issue Feb 27, 2013 · 10 comments

Comments

@lyrixx
Copy link
Member
lyrixx commented Feb 27, 2013

I would like to know if it is possible to mix validation group and group sequence ?

I used GroupSequence like this :

 * @Assert\GroupSequence({"Branch", "Step2"})
 * @ProjectAssert\Configuration(groups={"Step2"})
 */
class Branch

    // some property with validator.
    // and
    /**
     * @SensioAssert\Yaml() 
     */
    private $configurationVariables;

    /**
     * @SensioAssert\Twig()
     */
    private $configurationTemplate;

And it works like a charm.

But now, I want to preview the branch configuration. So I do not need validate everything. I just want to validate configurationVariables and configurationTemplate in a first step, and then the whole configuration with ProjectAssert\Configuration in a second step.

So I added groups={"preview"} on configurationVariables and configurationTemplate.
But I do not know how to add a group on my validation sequence.
AFAIK, a POPO can attach only one GroupSequence, and a GroupSequence can not be inside a group.

@francisbesset
Copy link
Contributor

👍

@webmozart
Copy link
Contributor

Hi! This seems to be a duplicate of #7146. Once this is implemented, you can simply do:

$validator->validate($branch, new GroupSequence(array('Preview', 'Branch', 'Step2'));

@lyrixx
Copy link
Member Author
lyrixx commented Feb 27, 2013

Thank you for your very good / fast support.

I read #7146 ; but I did not really understand this issue.

I do not understand something else: in $validator->validate($branch, new GroupSequence(array('Preview', 'Branch', 'Step2')); The Branch means all Validators in the DEFAULT group ?
And If I do that, All validators which are not in a group will be triggered ? ( I do not want to triggered them)
And will it working with annotation with annotation in POPO ?

And my last question, have you a ETA for this feature ? (I really don't want to push you, really)

Thanks, again

@webmozart
Copy link
Contributor

And If I do that, All validators which are not in a group will be triggered ?

Yes, the example I gave was just exemplary. The point is that you will be able to pass custom group sequences at validation time (also by passing them to the valdidation_groups option in the Form component).

Unfortunately no ETA yet, but you're welcome to send a PR ;)

@shinab
Copy link
shinab commented Dec 5, 2016

PR #10287 should correct it right ? Does it still work ?
I'm working on a project with same needs : mix GroupSequence and validation_groups.
GroupSequence alone is working as expected, but when I add validation_groups in Type class it's not working anymore.

@HeahDude
Copy link
Contributor
HeahDude commented Dec 5, 2016

@shinab can you fork symfony standard and add the minimum of code to reproduce your issue? Thanks!

@shinab
Copy link
shinab commented Dec 6, 2016

Fork is here https://github.com/shinab/symfony-standard

Test scenario
Put a dot in the field and valid

With current implementation, validation should fail directly after group3, but it passed thougt group2 and group1 too.

If you comment validation_groups in MyEntityType, validation fail after group1 as expected.

@shinab
Copy link
shinab commented Dec 9, 2016

Any news on this ? May I have to open a new issue ?

@HeahDude
Copy link
Contributor
HeahDude commented Dec 9, 2016

Yes you can, sorry I'll try to find some time this week-end to look at it.

@vkhramtsov
Copy link
Contributor
vkhramtsov commented Dec 26, 2016

It looks working when you create GroupSequence separately and set object to validation_groups

$sequence = new GroupSequence(array());
$sequence->cascadedGroup = new GroupSequence(['group3', 'group2']);
$resolver->setDefaults([
    'data_class' => 'AppBundle\Entity\MyEntity',
    'validation_groups' => $sequence,
]);

Checked on Symfony 2.8.14

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

No branches or pull requests

6 participants
0