In Twig template I check if a field has an error like this:
{% if form.points.get(\'errors\') is not empty %}
Is there any method like:
better way I found, is to use this kind of code
{% if not form.vars.valid %}
<div class="alert alert-error">
{{ form_errors(form) }}
</div>
{% endif %}
If you are using symfony 4, you can check errors existence with this code
{% if form_errors(registrationForm) %}
<div class="alert alert-danger">
{{ form_errors(registrationForm) }}
</div>
{% endif %}
This is what i use :
<div class="form-group {{ form.brand.vars.errors|length > '' ? 'has-error' }}">
i have create a twig extension to handle this: my extension
public function hasError($string)
{
if(strlen($string) > 4)
return true;
return false;
}
i use it like this in twig
{{ has_error(form_errors(form.username)) ? form_errors(form.username) : '' }}