| 756 | Highlighting required fields in templates |
| 757 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 758 | |
| 759 | You may wish to show a visitor which fields are required. Here is the above |
| 760 | example modified to insert an asterix after the label of each required field. |
| 761 | |
| 762 | <form method="post" action=""> |
| 763 | <dl> |
| 764 | {% for field in form %} |
| 765 | <dt>{{ field.label_tag }}{{ field.label }}{% if field.field.required %}*{% endif %}</dt> |
| 766 | <dd>{{ field }}</dd> |
| 767 | {% if field.help_text %}<dd>{{ field.help_text }}</dd>{% endif %} |
| 768 | {% if field.errors %}<dd class="myerrors">{{ field.errors }}</dd>{% endif %} |
| 769 | {% endfor %} |
| 770 | </dl> |
| 771 | <input type="submit" /> |
| 772 | </form> |
| 773 | |
| 774 | The ``{% if field.field.required %}*{% endif %}`` part adds the asterix only if |
| 775 | the field is required. Note that "field" is repeated twice because "field" in |
| 776 | the template is a newforms.forms.BoundField instance. |
| 777 | |