• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

292
Vistas
How to use group sequence on form type in symfony forms?

The idea is to first validate if all the required fields are not blank. If all the required data is provided then validate if the values entered are correct. The usual case for groups sequence. How ever when I apply new GroupSequence(["Basic", "Strict"]) to the validation_groups option it turns out the form to be valid even if all the fields are blank. If validation_groups value is set to ["Basic", "Strict"] the form is validated properly but with all constraints, and that is not what I want. What am I doing wrong?

Here is my code:

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"])
        ]);
    }
}
over 3 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

What am I doing wrong?

This is a known bug of Symfony version 2.8 and is fixed newer versions.

But I also did not see any documentation which shows that you can use a GroupSequence when configue the validation_groups option.

I would assume that when using Symfony 2.8 a custom validator which takes care of all validation is the best choice of handling such a situation.

over 3 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda