Fixed #23690 - fixed examples of manual rendering of form fields

Documentation for rendering form fields manually is now updated to use fields id_for_label instead of hardcoded values with additional mention of label_tag for alternative generation of complete label tag.
This commit is contained in:
nmundar 2014-11-15 13:29:16 +01:00
parent 4f90c99635
commit 48515ee1f7
1 changed files with 16 additions and 4 deletions

View File

@ -527,25 +527,37 @@ in a Django template, will be rendered appropriately. For example:
{{ form.non_field_errors }} {{ form.non_field_errors }}
<div class="fieldWrapper"> <div class="fieldWrapper">
{{ form.subject.errors }} {{ form.subject.errors }}
<label for="id_subject">Email subject:</label> <label for="{{ form.subject.id_for_label }}">Email subject:</label>
{{ form.subject }} {{ form.subject }}
</div> </div>
<div class="fieldWrapper"> <div class="fieldWrapper">
{{ form.message.errors }} {{ form.message.errors }}
<label for="id_message">Your message:</label> <label for="{{ form.message.id_for_label }}">Your message:</label>
{{ form.message }} {{ form.message }}
</div> </div>
<div class="fieldWrapper"> <div class="fieldWrapper">
{{ form.sender.errors }} {{ form.sender.errors }}
<label for="id_sender">Your email address:</label> <label for="{{ form.sender.id_for_label }}">Your email address:</label>
{{ form.sender }} {{ form.sender }}
</div> </div>
<div class="fieldWrapper"> <div class="fieldWrapper">
{{ form.cc_myself.errors }} {{ form.cc_myself.errors }}
<label for="id_cc_myself">CC yourself?</label> <label for="{{ form.cc_myself.id_for_label }}">CC yourself?</label>
{{ form.cc_myself }} {{ form.cc_myself }}
</div> </div>
Complete ``<label>`` element can also be generated using the
:meth:`~django.forms.BoundField.label_tag`. For example:
.. code-block:: html+django
<div class="fieldWrapper">
{{ form.subject.errors }}
{{ form.subject.label_tag }}
{{ form.subject }}
</div>
Rendering form error messages Rendering form error messages
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^