diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/forms/widgets.txt | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/docs/ref/forms/widgets.txt b/docs/ref/forms/widgets.txt index 2b386c0864..b657be4c53 100644 --- a/docs/ref/forms/widgets.txt +++ b/docs/ref/forms/widgets.txt @@ -345,7 +345,8 @@ commonly used groups of widgets: .. class:: RadioSelect - Similar to :class:`Select`, but rendered as a list of radio buttons: + Similar to :class:`Select`, but rendered as a list of radio buttons within + ``<li>`` tags: .. code-block:: html @@ -354,6 +355,40 @@ commonly used groups of widgets: ... </ul> + .. versionadded:: 1.4 + + For more granular control over the generated markup, you can loop over the + radio buttons in the template. Assuming a form ``myform`` with a field + ``beatles`` that uses a ``RadioSelect`` as its widget: + + .. code-block:: html+django + + {% for radio in myform.beatles %} + <div class="myradio"> + {{ radio }} + </div> + {% endfor %} + + This would generate the following HTML: + + .. code-block:: html + + <div class="myradio"> + <label><input type="radio" name="beatles" value="john" /> John</label> + </div> + <div class="myradio"> + <label><input type="radio" name="beatles" value="paul" /> Paul</label> + </div> + <div class="myradio"> + <label><input type="radio" name="beatles" value="george" /> George</label> + </div> + <div class="myradio"> + <label><input type="radio" name="beatles" value="ringo" /> Ringo</label> + </div> + + If you decide not to loop over the radio buttons, they'll be output in a + ``<ul>`` with ``<li>`` tags, as above. + ``CheckboxSelectMultiple`` ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
