summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2017-01-23 04:44:57 -0800
committerTim Graham <timograham@gmail.com>2017-01-23 07:44:57 -0500
commit88183117c28a8d669054e9064e7bd4de19ebcd28 (patch)
tree1b8766b08b395c35514b13b41a0411deff81bfb8
parentecd5944666558bbb3a12b0aa0058685a81ce7162 (diff)
Fixed #27761 -- Fixed quote location in multiple_input.html forms templates.
-rw-r--r--django/forms/jinja2/django/forms/widgets/multiple_input.html2
-rw-r--r--django/forms/templates/django/forms/widgets/multiple_input.html2
-rw-r--r--tests/forms_tests/widget_tests/test_checkboxselectmultiple.py35
3 files changed, 37 insertions, 2 deletions
diff --git a/django/forms/jinja2/django/forms/widgets/multiple_input.html b/django/forms/jinja2/django/forms/widgets/multiple_input.html
index be3d449926..349db54104 100644
--- a/django/forms/jinja2/django/forms/widgets/multiple_input.html
+++ b/django/forms/jinja2/django/forms/widgets/multiple_input.html
@@ -1,5 +1,5 @@
{% set id = widget.attrs.id %}<ul{% if id %} id="{{ id }}"{% endif %}>{% for group, options, index in widget.optgroups %}{% if group %}
- <li>{{ group }}<ul{% if id %} id="{{ id }}_{{ index }}{% endif %}">{% endif %}{% for widget in options %}
+ <li>{{ group }}<ul{% if id %} id="{{ id }}_{{ index }}"{% endif %}>{% endif %}{% for widget in options %}
<li>{% include widget.template_name %}</li>{% endfor %}{% if group %}
</ul></li>{% endif %}{% endfor %}
</ul>
diff --git a/django/forms/templates/django/forms/widgets/multiple_input.html b/django/forms/templates/django/forms/widgets/multiple_input.html
index 60282ff887..2362aff4e6 100644
--- a/django/forms/templates/django/forms/widgets/multiple_input.html
+++ b/django/forms/templates/django/forms/widgets/multiple_input.html
@@ -1,5 +1,5 @@
{% with id=widget.attrs.id %}<ul{% if id %} id="{{ id }}"{% endif %}>{% for group, options, index in widget.optgroups %}{% if group %}
- <li>{{ group }}<ul{% if id %} id="{{ id }}_{{ index }}{% endif %}">{% endif %}{% for option in options %}
+ <li>{{ group }}<ul{% if id %} id="{{ id }}_{{ index }}"{% endif %}>{% endif %}{% for option in options %}
<li>{% include option.template_name with widget=option %}</li>{% endfor %}{% if group %}
</ul></li>{% endif %}{% endfor %}
</ul>{% endwith %}
diff --git a/tests/forms_tests/widget_tests/test_checkboxselectmultiple.py b/tests/forms_tests/widget_tests/test_checkboxselectmultiple.py
index a92e5533e2..6ec5c78803 100644
--- a/tests/forms_tests/widget_tests/test_checkboxselectmultiple.py
+++ b/tests/forms_tests/widget_tests/test_checkboxselectmultiple.py
@@ -78,6 +78,41 @@ class CheckboxSelectMultipleTest(WidgetTest):
attrs={'id': 'media'}, html=html,
)
+ def test_nested_choices_without_id(self):
+ nested_choices = (
+ ('unknown', 'Unknown'),
+ ('Audio', (('vinyl', 'Vinyl'), ('cd', 'CD'))),
+ ('Video', (('vhs', 'VHS'), ('dvd', 'DVD'))),
+ )
+ html = """
+ <ul>
+ <li>
+ <label><input name="nestchoice" type="checkbox" value="unknown" /> Unknown</label>
+ </li>
+ <li>Audio<ul>
+ <li>
+ <label>
+ <input checked name="nestchoice" type="checkbox" value="vinyl" /> Vinyl
+ </label>
+ </li>
+ <li>
+ <label><input name="nestchoice" type="checkbox" value="cd" /> CD</label>
+ </li>
+ </ul></li>
+ <li>Video<ul>
+ <li>
+ <label><input name="nestchoice" type="checkbox" value="vhs" /> VHS</label>
+ </li>
+ <li>
+ <label>
+ <input checked name="nestchoice" type="checkbox" value="dvd" /> DVD
+ </label>
+ </li>
+ </ul></li>
+ </ul>
+ """
+ self.check_html(self.widget(choices=nested_choices), 'nestchoice', ('vinyl', 'dvd'), html=html)
+
def test_separate_ids(self):
"""
Each input gets a separate ID.