Reputation: 23
I'm using Symfony 4.1 and have a strange behaviour with form validation. Some errors are rendered in the label and some are not.
The entity looks like:
class Vehicle
{
/**
* @ORM\Column(type="string", length=64)
* @Assert\NotBlank(
* groups = { "edit" },
* message="Fahrzeugnummer wird benötigt"
* )
*/
private $fzgnr_nvr;
/**
* @ORM\Column(type="string", length=64)
* @Assert\NotBlank(
* groups = { "edit" },
* message="Hersteller wird benötigt"
* )
*/
private $hersteller;
Here is the formbuilder
$builder
->add('fzgnrNvr', TextType::class, [
'label' => 'Fahrzeug (NVR)',
])
->add('histbezMitnr', TextType::class, [
'label' => 'Historische Bezeichnung'
])
->add('hersteller', TextType::class, [
'label' => 'Hersteller'
])
The twig looks like
{{ form_start(form) }}
{{ form_errors(form) }}
{{ form_row(form.fzgnrNvr) }}
{{ form_row(form.histbezMitnr) }}
{{ form_row(form.hersteller) }}
{{ form_row(form.baujahr) }}
{{ form_row(form.eigentuemer) }}
form_errors I have added because then the error for form.fzgnrNvr are not rendered. The errors where rendered different and I cannot find what is wrong.1
In the debug the error is shown but not at the field. fzgnrNvr and hersteller are absolutely the same but renders the error different.2
Upvotes: 0
Views: 624
Reputation: 23
Problem was the underscore in the database fields. Fields should not be named fzgnr_nvr but fzgnrnvr or fzgnrNvr. After removing all underscores from the database fields everything works as it should.
Upvotes: 2