- Author:
- epicserve
- Posted:
- September 29, 2008
- Language:
- HTML/template
- Version:
- Not specified
- Score:
- 0 (after 6 ratings)
You can place this code above your form and it will list out all errors in your form if there are errors. Sometimes I like listing the errors at the top of the form because I think it looks cleaner. Make sure you add error_messages={'required': 'My detailed error here'} in your view.py for your form.
1 2 3 4 5 6 7 8 9 10 | {% if form.errors %}
<div id="form-error">
<p>The operation could not be performed because one or more error(s) occurred.<br />Please resubmit the form after making the following changes:</p>
<ul>
{% for field in form %}
<li>{{ field.errors|striptags }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
|
More like this
- Bootstrap Accordian by Netplay4 5 years, 11 months ago
- Bootstrap theme for django-endless-pagination? by se210 8 years, 11 months ago
- Bootstrap theme for django-endless-pagination? by se210 8 years, 11 months ago
- Reusable form template with generic view by roldandvg 9 years ago
- Pagination Django with Boostrap by guilegarcia 9 years, 2 months ago
Comments
replace < li>{{ field.errors|striptags }}< /li>
with: {% if field.errors %}< li>{{ field.errors|striptags }}< /li>{% endif %}
so that fields with no error don't show up as an empty < li> element
p.s. remove the spaces i've put in the li tags, this site doesn't let me paste html! eurgh
#
This is a better one, it shows field name to clarify the "this field is required" message.
<div class="alert alert-error"> The operation could not be performed because one or more error(s) occurred{% for field,error in form.errors.items %}- {{field}} - {{ error|striptags }}
{% endfor %}
</div>#
Please login first before commenting.