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:
@@ -129,6 +129,17 @@
|
|||||||
|
|
||||||
<form method="POST" class="post-form">
|
<form method="POST" class="post-form">
|
||||||
{% csrf_token %}
|
{% 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 #}
|
{# Render example_form fields explicitly so we can improve error UX for json_answer #}
|
||||||
{% for field in example_form %}
|
{% for field in example_form %}
|
||||||
{% if field.name == 'json_answer' %}
|
{% if field.name == 'json_answer' %}
|
||||||
@@ -163,6 +174,23 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% 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>
|
<button type="submit" value="answer" name="submit">Save Correct Answers</button>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user