formstexttwigmessagesymfony4

How to get only text instead of list item from form_errors


I'm trying to display an error message for a repeated password field in Symfony 4.4.

Here is the relevant code in the form class file:

->add('password', RepeatedType::class, array(
            'required' => true,
            'invalid_message' => 'Le mot de passe et sa confirmation ne sont pas identiques',
            'type' => PasswordType::class,
            'first_options' => array('label' => false,'error_bubbling' => true),
            'second_options' => array('label' => false),
        ))

And here is my relevant twig/HTML code:

<div class="col-md-4 mb-4">
    <div class="form-outline">
         {{ form_row(registrationForm.password.first ,{'label':false,'attr':{'placeholder':'Mot de passe', 'name':'password1', 'class':'form-control', 'id':'password1'} } ) }}
         <span style="color: red">{{ form_errors(registrationForm.password|first) }}</span>
     </div>
</div>

Actually, if I change form_errors(registrationForm.password|first) to form_errors(registrationForm.password), I get this:

enter image description here

However, that is not the wanted result since I need to display only a simple text, and I really wonder why form_errors(registrationForm.password|first) didn't work for me. Any idea?


Solution

  • I've fixed it! I've actually followed a different approach. In my HTML\Twig code, I've changed this line <span style="color: red">{{ form_errors(registrationForm.password|first) }}</span> like so:

    <span class="Errormessage" style="color: red;text-align: right">{{ form_errors(registrationForm.password) }}</span>

    Then, I added the code below in my CSS code:

    .Errormessage li {
        list-style-type: none !important;
    }