Skip to content

[Validator][GroupSequences] GroupSequences execute next group if first fail #22373

Closed
@devpetrov

Description

@devpetrov
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 2.8.19

This issue appears when form is used without entity/data_class. Both groups "Basic' and 'Strict' are validated even if there are violations in 'Basic'.

I also get the error: The Symfony\Component\Validator\Constraints\GroupSequence::getIterator method is deprecated since version 2.5 and will be removed in 3.0. in Symfony\Component\Validator\Constraints\GroupSequence.php on line 107 which is caused in by Symfony\Component\Form\Extension\Validator\Constraints\FormValidator.php:(84)

The Form and Validator components are working standalone outside of symfony distribution, with all the dependencies also available.

Here is how the form is configured:

class MyType extends AbstractType
{

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
                ->add("name", null, [
                    "constraints" => new NotBlank(["groups" => ["Basic"]])
                ])
                ->add("phone", MyPhoneType::class, [
                    "constraints" => [
                        new NotBlank(["groups" => ["Basic"]]),
                        new PhoneNumber(["groups" => ["Strict"])
                    ]
                ])
                ->add("email", EmailType::class, [
                    "constraints" => [
                        new NotBlank(["groups" => ["Basic"]]),
                        new Email(["groups" => ["Strict"]]),
                    ],
                ])
            ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            "validation_groups" => new GroupSequence(["Basic", "Strict"])
        ]);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions