Distinguish between bubbled errors and field error

2019-08-26 09:59发布

问题:

How can i distinguish between field errors and bubbled (form) errors? AFAIK the only block that controls this is:

{% block field_errors %}
{% spaceless %}
    {% if errors|length > 0 %}
    <ul>
        {% for error in errors %}
        ...
        {% endfor %}
    </ul>
    {% endif %}
{% endspaceless %}
{% endblock field_errors %}

I think i can't rely on errors|length: usually it's 1 for field errors, but can be 1 also for form errors :(

回答1:

To me it looks like by default you are unable to separate these errors. But you can extend the basic FormError class and add some property, which will define the exact place where error appeared.