4

Is it possible to only render field errors with crispy-forms? I tried using setting form_show_errors = False but that disables all errors.

The problem I'm having is that i want to use custom non_field_errors but at the moment they get rendered twice.

Source:

{% if form.non_field_errors %}
      <div class="alert alert-danger" style="margin-bottom: 0;">
        <span class="pficon pficon-error-circle-o"></span>
        {% for err in form.non_field_errors %}
        <p>{{ err }}</p>
        {% endfor %}
      </div>
      {% endif %}

    </div>
  </div>
  <div class="row">
      {% crispy form form.helper %}
  </div>

Error: enter image description here

1 Answer 1

1

You could try overriding the display_form.html template. You haven't said which layout you are using, so as an example, here is the bootstrap3 version.

Duplicating the template is not ideal, but it's less than 10 lines, so it's not so bad.

Leave out the if statement that includes the non-form errors,

{% if form_show_errors %}
    {% include "bootstrap3/errors.html" %}
{% endif %}

then set form_show_errors back to True in your form.

Alternatively, you might want to override the errors.html template instead, and put your custom layout for non_field_errors there.

See the docs on overriding layout templates for more info.

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

Comments

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.