diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2011-12-07 22:31:39 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2011-12-07 22:31:39 +0000 |
| commit | fc90c09efdfbc029d43e6d4c0952ed6b49f6f34d (patch) | |
| tree | b86bdd032d4afc93cb3135312377cf02532dc68d /docs/ref | |
| parent | 0519adb2a87090bd9ee3f61c7b9a6ff6de5fa341 (diff) | |
Made BoundFields iterable, so that you can iterate over individual radio buttons of a RadioSelect in a template
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17173 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/ref')
| -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`` ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
