Jeboy
Jeboy

Reputation: 228

Is it possible to extend the behavior of Symfony2 form_row()?

Is it possible to add a class in the div container when there's an error in that field? For example adding class has-error to the class attribute of the div container

{% block field_row %}
    <div class="form_row has-error">
        {{ form_label(form) }}
        {{ form_errors(form) }}
        {{ form_widget(form) }}
    </div>
{% endblock field_row %}

Upvotes: 1

Views: 102

Answers (1)

Nicolai Fr&#246;hlich
Nicolai Fr&#246;hlich

Reputation: 52493

{% block field_row %}
    <div class="form_row{% if form_errors(form) %} has-error{% endif %}">
        {{ form_label(form) }}
        {{ form_errors(form) }}
        {{ form_widget(form) }}
    </div>
{% endblock field_row %}

Upvotes: 1

Related Questions