1

Right now my errors theme looks like this:

{% form_theme form _self %}
{% block form_errors %}
    {% for child in form %}
        {% for error in child.vars.errors %}
            <div class="alert alert-danger fade in margin-bottom-40">
                <h4>{{ child.vars.label|trans }}</h4>
                {{ error.message|trans }}
            </div>
        {% endfor %}
    {% endfor %}
{% endblock form_errors %}

and this is fine until I add error to the whole entity, not to particular field. My validator is doing something like this:

$this->context->buildViolation($constraint->message)
              ->addViolation();

Then the error message isn't shown, what is obvious.

What I want to do is to keep current schema of showing errors associated with fields and add something similar to errors for whole entity/form. Do You guys have any ideas?

1 Answer 1

1

Since you're adding putting the violation on the Entity itself, it will go on the root form so put something like:

{% for errors in form.vars.errors %}
<div class="alert alert-danger fade in margin-bottom-40">
      {{ error.message|trans }}
</div>
{% endfor %}

before rendering the errors for the form's children.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, enough is just {% for error in errors %}, but Your answer is ok too :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.