- Author:
- brunobord
- Posted:
- November 20, 2007
- Language:
- HTML/template
- Version:
- Not specified
- Score:
- 6 (after 8 ratings)
the trick resides in field.field.required
. The intuitive way of testing this in the templates is to access field.required
. But it's not the good one. Enjoy!
1 2 3 4 5 6 7 8 9 | {% for field in form %}
<div>
<label for="{{ field.label }}">{{ field.label_tag }}
{% if field.field.required %}<span class="special_class">*</span>{% endif %}</label>
{{ field }}
</div>
{% endfor %}
|
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
It should be
<label for="{{ field.auto_id }}">
(the id generated in the input,select and texarea fields)
#
Would be nice to see the snippet for this as a custom template tag
#
One may instead wrap the label text in a span with class="required", allowing an asterisk to be added via CSS:
This provides a useful hook for additional styling as well. For example, one might do the following:
This will further differential required from non-required fields.
#
The code should look more like this:
Combine with davidchambers styles for effect.
#
Please login first before commenting.