{% macro errorlist(form, safe=False) -%}
  {% if form.errors %}
    <ul class="errorlist">
      {% for field in form %}
        {% for error in field.errors %}
          <li><a href="#{{ form.auto_id % field.name }}">{{ error|safe if safe else error }}</a></li>
        {% endfor %}
      {% endfor %}
      {% for error in form.non_field_errors() %}
        <li>{{ error|safe if safe else error }}</li>
      {% endfor %}
    </ul>
  {% endif %}
{%- endmacro %}
