I'm trying to customize the display of this error message "There is already an account with this" in Twig.
This is the relevant code in the form class:
->add('cin', TextType::class, [
'required' => true,
])
And here is the relvant HTML/Twig code:
<div class="form-outline">
{{ form_row(registrationForm.cin ,{'label':false,'attr':{'placeholder':'Numéro carte d\'identité', 'name':'cin', 'class':'form-control', 'id':'cin', 'type':'number', 'minlength':'8', 'maxlength':'8', 'required data-error':'Veuillez saisir votre numéro de carte d\'identité', } } ) }}
<span style="color: red">{{ form_errors(registrationForm.cin) }}</span>
</div>
This is what I get on my screen in case there is an error:
However, What I would like to get is only the red message (that is below the text field) customized to something like "Invalid card ID", for instance. So, what's wrong in my code? Any idea?
After some more research we identified that the error message can be changed in the @UniqueEntity
validator in the user class.
Changing the current validator from
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"cin"}, message="There is already an account with this cin")
*/
to
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"cin"}, message="Invalid card id")
*/
results in the validation error message acutally being modified accordingly.