Skip to content

Issue with "has-error" class on <form> element #263

Closed
@althaus

Description

Hey,

I stumbled upon an issue with the form (error) rendering. This code snippet in the form_start Twig block leads to bad form error rendering:

{% block form_start %}
    {% spaceless %}
        ...
        {% if form.vars.errors|length > 0 %}
            {% set attr = attr|merge({ 'class': (attr.class|default('') ~ ' has-error')|trim }) %}
        {% endif %}

https://github.com/braincrafted/bootstrap-bundle/blob/develop/Resources/views/Form/bootstrap.html.twig#L739

The result is that all children are rendered as they have errors themselves, because the CSS from Bootstrap is simply

.has-error .help-block, ... {
    color: #a94442;
}

I don't know if there's a reason behind adding that class to the form root as Bootstrap hasn't anything about that in their docs. I fixed this by overriding the Twig block and renaming the error class there.

Cheers
Matthias

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions