Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested forms dont show error messages #37091

Closed
sandbava opened this issue Jun 4, 2020 · 7 comments
Closed

nested forms dont show error messages #37091

sandbava opened this issue Jun 4, 2020 · 7 comments

Comments

@sandbava
Copy link

sandbava commented Jun 4, 2020

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) }}
//[...]
@xabbuh
Copy link
Member

xabbuh commented Jun 4, 2020

Is this the same as #37025 and #37027?

@sandbava
Copy link
Author

sandbava commented Jun 4, 2020

Different problem

@xabbuh
Copy link
Member

xabbuh commented Jun 4, 2020

Can you then please create a small example application that allows to reproduce your issue?

@sandbava
Copy link
Author

sandbava commented Jun 4, 2020

githubdemo.zip

@xabbuh
Copy link
Member

xabbuh commented Jun 4, 2020

@sandbava Thank you for the example. However, this works for me when I apply the patch from #37085.

@sandbava
Copy link
Author

sandbava commented Jun 4, 2020

I confirm, the patch do the work.
Will it be applied to version 5.1 ? Because I see it was for version 3.4.

@xabbuh
Copy link
Member

xabbuh commented Jun 4, 2020

Yes, we merge bugfixes in the lowest affected branch that is still maintained and from there merge it up to all other maintained branches.

@xabbuh xabbuh closed this as completed Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants