add a fieldset.errors dictionary to use in templates
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
django-form-utils |
Fix Committed
|
Wishlist
|
Unassigned |
Bug Description
I propose with one patch a change that allow to have a fieldset.errors, that is a dict grouping all errors of fieldset fields.
Example:
form = EnhancedForm({})
for fs in form:
print fs.errors
Example output:
{'category': {'errorlist': [u'This field is required.'], 'label': u'Category'},
'manufacturer': {'errorlist': [u'This field is required.'], 'label': u'Manufacturer'}}
The great use is in templates:
{% for errors in fieldset.
{% if forloop.first %}
<ul class="errors">
{% endif %}
<li>{{ errors.label }}: {% for e in errors.errorlist %}{{ e }}{% if not forloop.last %}, {% endif %}{% endfor %}</li>
{% if forloop.last %}
</ul>
{% endif %}
{% endfor %}
I attach the patch and generic template that I using this change.
Good idea. I would prefer to see the fieldset errors be a property calculated on demand rather than assigned at FieldSet creation, but I can easily make that change. Thanks!