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:
parent
4f90c99635
commit
48515ee1f7
|
@ -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
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue