I am trying to implement bootstrap styles when the form has errors, and I have succeeded ... but in a very tedious way. For example:
<div class="form-group">
{{ form_label(form.name) }}
{{ form_widget(form.name) }}
{{ form_errors(form.name) }}
</div>
When there is an error in the form, I would like to add the "has-danger" class to the corresponding divs to customize the view. In this way it would be like this:
<div class="form-group has-danger">
{{ form_label(form.name) }}
{{ form_widget(form.name) }}
{{ form_errors(form.name) }}
</div>
I have come up with a not very pretty way to do it:
<div class="form-group {% if form.name.vars.errors|length > 0 %}has-danger{% endif %}">
The problem is that I would have to add this code to all the fields of all the forms on my website, which I do not see well.
Any ideas? Thank you.