diff options
| author | David Smith <smithdc@gmail.com> | 2022-05-05 09:21:47 +0200 |
|---|---|---|
| committer | Carlton Gibson <carlton@noumenal.es> | 2022-05-05 14:32:43 +0200 |
| commit | ec5659382a5f5fc2daf0c87ccc89d0fb07534874 (patch) | |
| tree | 08a5183708f3490b97f61098d26272901d25b822 /docs/ref/forms | |
| parent | 27b07a3246bc033cd9ded01238c6dc64731cce35 (diff) | |
Fixed #32339 -- Added div.html form template.
Diffstat (limited to 'docs/ref/forms')
| -rw-r--r-- | docs/ref/forms/api.txt | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index 8530af2611..72937bfa9a 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -607,6 +607,55 @@ list using ``{{ form.as_ul }}``. Each helper pairs a form method with an attribute giving the appropriate template name. +``as_div()`` +~~~~~~~~~~~~ + +.. attribute:: Form.template_name_div + +.. versionadded:: 4.1 + +The template used by ``as_div()``. Default: ``'django/forms/div.html'``. + +.. method:: Form.as_div() + +.. versionadded:: 4.1 + +``as_div()`` renders the form as a series of ``<div>`` elements, with each +``<div>`` containing one field, such as: + +.. code-block:: pycon + + >>> f = ContactForm() + >>> f.as_div() + +… gives HTML like: + +.. code-block:: html + + <div> + <label for="id_subject">Subject:</label> + <input type="text" name="subject" maxlength="100" required id="id_subject"> + </div> + <div> + <label for="id_message">Message:</label> + <input type="text" name="message" required id="id_message"> + </div> + <div> + <label for="id_sender">Sender:</label> + <input type="email" name="sender" required id="id_sender"> + </div> + <div> + <label for="id_cc_myself">Cc myself:</label> + <input type="checkbox" name="cc_myself" id="id_cc_myself"> + </div> + +.. note:: + + Of the framework provided templates and output styles, ``as_div()`` is + recommended over the ``as_p()``, ``as_table()``, and ``as_ul()`` versions + as the template implements ``<fieldset>`` and ``<legend>`` to group related + inputs and is easier for screen reader users to navigate. + ``as_p()`` ~~~~~~~~~~ |
