undefinedman
undefinedman

Reputation: 670

Constraints versus validation groups in Symfony2

I have enabled validation_groups in my form by

    $resolver->setDefaults([
        'translation_domain'    => 'general',
        'data_class'            => 'Software\Bundle\Entity\User',
        'attr'                  => ['novalidate' => 'novalidate'],
        'cascade_validation'    => true,
        'validation_groups'     => ['registration']
    ]);

and User.yml file contains

    emailAddress:
        - NotBlank:
            groups: [registration]

However in my form builder method I do have extra custom constraint

    $options = [
        'label' => 'word.email_address',
        'constraints'=> [
            new HasUsername($this->getOption('uuid'))
        ]
    ];

    return $builder->add('emailAddress', 'email', $options);

Problem is that the one from form builder is never called due to the fact that validation_groups is enabled. Because when I disable validation_groups then custom one is being called.

Is it possible to have the validation_groups constrains and constraints in the form builder work at the same time together?

The reason I need to call custom constraint in form builder is because I need to pass important variable uuid in order to check properly to which uuid user belongs to.

Upvotes: 0

Views: 110

Answers (1)

debugall
debugall

Reputation: 310

Use Default in your validation group attribute

'validation_groups'     => ['registration', 'Default']

Upvotes: 2

Related Questions