Skip to content
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

[Form] ValidationListener validates only "Default" group #12477

Closed
korotovsky opened this issue Nov 14, 2014 · 2 comments
Closed

[Form] ValidationListener validates only "Default" group #12477

korotovsky opened this issue Nov 14, 2014 · 2 comments
Labels

Comments

@korotovsky
Copy link
Contributor

https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/Extension/Validator/EventListener/ValidationListener.php#L64

// Validate the form in group "Default"
$violations = $this->validator->validate($form);

Is it correct? Because in this example the Custom group never will be validated.

    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('foo', 'hidden', [
            'constraints' => [
                new NotBlank(),
            ],
            'validation_groups' => [
                Constraint::DEFAULT_GROUP,
            ],
        ]);
        $builder->add('bar', 'hidden' , [
            'constraints' => [
                new NotBlank(),
            ],
            'validation_groups' => [
                'Custom',
            ],
        ]);
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults([
            'validation_groups' => [
                Constraint::DEFAULT_GROUP,
                'Custom',
            ],
        ]);
    }
@origaminal
Copy link
Contributor

Yes, it is correct. Validation groups for Form's Data are retrieved into the https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php with FormValidator::getValidationGroups

Look also here
https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/Resources/config/validation.xml

@fabpot fabpot added the Form label Jan 2, 2015
@javiereguiluz
Copy link
Member

Closing it because this doesn't look like a bug. As @origaminal said, validation groups are indeed taken into account to validate the forms.

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

4 participants