Closed
Description
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) }}
//[...]