8000 nested forms dont show error messages · Issue #37091 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
nested forms dont show error messages #37091
Closed
@sandbava

Description

@sandbava

Symfony version(s) affected: 5.0.9 (also in 5.1.0)

Description
Since my last composer install (3 June 2020), my nested forms (other form fields are ok) don't show error messages in html form anymore.
For example one field is instantiated like this in twig {{ form_row(form.birthplace.postal_code) }}.
If I put a wrong postal code in the html form, Symfony doesn't validate my form (correct behavior) but won't show error message corresponding to my constraints (incorrect behavior).

How to reproduce

PHP

nested form :

class BirthPlaceType extends AbstractType
{

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('postal_code', TextType::class, [
                'label' => 'Postal code',
                'property_path' => 'birthplace.postalCode',
                'required' => true,
                'constraints' => [
                    new NotBlank(),
                    new Regex([
                        'pattern' => '/^(?:[0-8]\d|9[0-8])\d{3}$/',
                        'message' => 'validator.address.postal_code'
                    ])
                ]
            ])),
//[...]

host form :

class RegistrationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('birthplace', BirthPlaceType::class, ['data_class' => UserProfile::class])
//[...]

controller :

class RegistrationController extends AbstractController
{
    public function form(Request $request)
    {
        $form = $this->createForm(RegistrationType::class, new UserProfile());
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            //[...]
        }

        return $this->render('registration/form.html.twig', ['form' => $form->createView()]);
    }
}

TWIG

form.html.twig

//[...]
{{ form_start(form) }}
{{ form_row(form.birthplace.postal_code) }}
//[...]
{{ form_end(form) }}
//[...]

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

      0