mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Refs #32338 -- Improved accessibility of RadioSelect examples in docs.
Co-authored-by: Thibaud Colas <thibaudcolas@gmail.com>
This commit is contained in:
parent
0393b9262d
commit
d8c17aa10c
2 changed files with 55 additions and 46 deletions
|
@ -718,28 +718,34 @@ that specifies the template used to render each choice. For example, for the
|
|||
|
||||
.. code-block:: html+django
|
||||
|
||||
{% for radio in myform.beatles %}
|
||||
<div class="myradio">
|
||||
{{ radio }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<fieldset>
|
||||
<legend>{{ myform.beatles.label }}</legend>
|
||||
{% for radio in myform.beatles %}
|
||||
<div class="myradio">
|
||||
{{ radio }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</fieldset>
|
||||
|
||||
This would generate the following HTML:
|
||||
|
||||
.. code-block:: html
|
||||
|
||||
<div class="myradio">
|
||||
<label for="id_beatles_0"><input id="id_beatles_0" name="beatles" type="radio" value="john" required> John</label>
|
||||
</div>
|
||||
<div class="myradio">
|
||||
<label for="id_beatles_1"><input id="id_beatles_1" name="beatles" type="radio" value="paul" required> Paul</label>
|
||||
</div>
|
||||
<div class="myradio">
|
||||
<label for="id_beatles_2"><input id="id_beatles_2" name="beatles" type="radio" value="george" required> George</label>
|
||||
</div>
|
||||
<div class="myradio">
|
||||
<label for="id_beatles_3"><input id="id_beatles_3" name="beatles" type="radio" value="ringo" required> Ringo</label>
|
||||
</div>
|
||||
<fieldset>
|
||||
<legend>Radio buttons</legend>
|
||||
<div class="myradio">
|
||||
<label for="id_beatles_0"><input id="id_beatles_0" name="beatles" type="radio" value="john" required> John</label>
|
||||
</div>
|
||||
<div class="myradio">
|
||||
<label for="id_beatles_1"><input id="id_beatles_1" name="beatles" type="radio" value="paul" required> Paul</label>
|
||||
</div>
|
||||
<div class="myradio">
|
||||
<label for="id_beatles_2"><input id="id_beatles_2" name="beatles" type="radio" value="george" required> George</label>
|
||||
</div>
|
||||
<div class="myradio">
|
||||
<label for="id_beatles_3"><input id="id_beatles_3" name="beatles" type="radio" value="ringo" required> Ringo</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
That included the ``<label>`` tags. To get more granular, you can use each
|
||||
radio button's ``tag``, ``choice_label`` and ``id_for_label`` attributes.
|
||||
|
@ -747,36 +753,39 @@ that specifies the template used to render each choice. For example, for the
|
|||
|
||||
.. code-block:: html+django
|
||||
|
||||
{% for radio in myform.beatles %}
|
||||
<fieldset>
|
||||
<legend>{{ myform.beatles.label }}</legend>
|
||||
{% for radio in myform.beatles %}
|
||||
<label for="{{ radio.id_for_label }}">
|
||||
{{ radio.choice_label }}
|
||||
<span class="radio">{{ radio.tag }}</span>
|
||||
</label>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</fieldset>
|
||||
|
||||
...will result in the following HTML:
|
||||
|
||||
.. code-block:: html
|
||||
|
||||
<label for="id_beatles_0">
|
||||
John
|
||||
<span class="radio"><input id="id_beatles_0" name="beatles" type="radio" value="john" required></span>
|
||||
</label>
|
||||
|
||||
<label for="id_beatles_1">
|
||||
Paul
|
||||
<span class="radio"><input id="id_beatles_1" name="beatles" type="radio" value="paul" required></span>
|
||||
</label>
|
||||
|
||||
<label for="id_beatles_2">
|
||||
George
|
||||
<span class="radio"><input id="id_beatles_2" name="beatles" type="radio" value="george" required></span>
|
||||
</label>
|
||||
|
||||
<label for="id_beatles_3">
|
||||
Ringo
|
||||
<span class="radio"><input id="id_beatles_3" name="beatles" type="radio" value="ringo" required></span>
|
||||
</label>
|
||||
<fieldset>
|
||||
<legend>Radio buttons</legend>
|
||||
<label for="id_beatles_0">
|
||||
John
|
||||
<span class="radio"><input id="id_beatles_0" name="beatles" type="radio" value="john" required></span>
|
||||
</label>
|
||||
<label for="id_beatles_1">
|
||||
Paul
|
||||
<span class="radio"><input id="id_beatles_1" name="beatles" type="radio" value="paul" required></span>
|
||||
</label>
|
||||
<label for="id_beatles_2">
|
||||
George
|
||||
<span class="radio"><input id="id_beatles_2" name="beatles" type="radio" value="george" required></span>
|
||||
</label>
|
||||
<label for="id_beatles_3">
|
||||
Ringo
|
||||
<span class="radio"><input id="id_beatles_3" name="beatles" type="radio" value="ringo" required></span>
|
||||
</label>
|
||||
</fieldset>
|
||||
|
||||
If you decide not to loop over the radio buttons -- e.g., if your template
|
||||
includes ``{{ myform.beatles }}`` -- they'll be output in a ``<ul>`` with
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue