mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
handle server-side form errors
This commit is contained in:
parent
d0cb7d843d
commit
59d8c0b321
26
netbox/templates/utilities/render_errors.html
Normal file
26
netbox/templates/utilities/render_errors.html
Normal 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 %}
|
@ -54,3 +54,13 @@ def widget_type(field):
|
||||
return field.field.widget.__class__.__name__.lower()
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
@register.inclusion_tag('utilities/render_errors.html')
|
||||
def render_errors(form):
|
||||
"""
|
||||
Render form errors, if they exist.
|
||||
"""
|
||||
return {
|
||||
"form": form
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user