Enhance error handling in example form by displaying non-field errors and providing a debug view for all form errors

This commit is contained in:
Ross
2025-10-01 20:09:36 +01:00
parent 0839eb7e37
commit 5400959399
@@ -129,6 +129,17 @@
<form method="POST" class="post-form">
{% csrf_token %}
{# Show example_form non-field errors first #}
{% if example_form.non_field_errors %}
<div class="alert alert-danger">
<strong>Errors:</strong>
<ul class="mb-0">
{% for err in example_form.non_field_errors %}
<li>{{ err }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{# Render example_form fields explicitly so we can improve error UX for json_answer #}
{% for field in example_form %}
{% if field.name == 'json_answer' %}
@@ -163,6 +174,23 @@
</div>
{% endif %}
{% endfor %}
{# Debug: list all example_form.errors (field -> [errors]) in a collapsed block so nothing is missed #}
{% if example_form.errors %}
<details style="margin-top:8px;">
<summary class="small">All example form errors (debug)</summary>
<ul class="mb-0">
{% for name, errs in example_form.errors.items %}
<li><strong>{{ name }}</strong>
<ul>
{% for e in errs %}
<li class="small text-muted">{{ e }}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</details>
{% endif %}
<button type="submit" value="answer" name="submit">Save Correct Answers</button>
</form>
{% endif %}