1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

handle server-side form errors

This commit is contained in:
checktheroads
2021-03-14 01:06:51 -07:00
parent d0cb7d843d
commit 59d8c0b321
2 changed files with 36 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
{% load form_helpers %}
{% if form.errors or form.non_field_errors %}
<div class="alert alert-danger mt-3" role="alert">
<h4 class="alert-heading">Errors</h4>
<hr />
<div class="ps-2">
{% if form.errors %}
{% for field_name, errors in form.errors.items %}
{% with field=form|getfield:field_name %}
<strong>{{ field.label }}</strong>
<ul>
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endwith %}
{% endfor %}
{% endif %}
{% if form.non_field_errors %}
<hr />
{{ form.non_field_errors }}
{% endif %}
</div>
</div>
{% endif %}