mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
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
This commit is contained in:
parent
0519adb2a8
commit
fc90c09efd
4 changed files with 87 additions and 1 deletions
|
@ -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``
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue