Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

346
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"])
        ]);
    }
}
about 4 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.

about 4 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda