Ticket #5854: django_newforms_doc_patch.patch

File django_newforms_doc_patch.patch, 1.2 KB (added by knox <christobzr@…>, 17 years ago)
  • docs/newforms.txt

     
    753753    </ul>
    754754    </form>
    755755
     756Highlighting required fields in templates
     757~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     758
     759You may wish to show a visitor which fields are required. Here is the above
     760example 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
     774The ``{% if field.field.required %}*{% endif %}`` part adds the asterix only if
     775the field is required. Note that "field" is repeated twice because "field" in
     776the template is a newforms.forms.BoundField instance.
     777
    756778Binding uploaded files to a form
    757779--------------------------------
    758780
Back to Top