Fixed #29041 -- Changed SelectMultiple's multiple attribute to HTML5 boolean syntax.

This commit is contained in:
Jon Dufresne 2018-01-20 08:19:06 -08:00 committed by Tim Graham
parent b98dc1706e
commit 47d238b696
10 changed files with 42 additions and 38 deletions

View File

@ -670,7 +670,7 @@ class Select(ChoiceWidget):
def get_context(self, name, value, attrs):
context = super().get_context(name, value, attrs)
if self.allow_multiple_selected:
context['widget']['attrs']['multiple'] = 'multiple'
context['widget']['attrs']['multiple'] = True
return context
@staticmethod

View File

@ -664,7 +664,7 @@ that specifies the template used to render each choice. For example, for the
* ``option_template_name``: ``'django/forms/widgets/select_option.html'``
Similar to :class:`Select`, but allows multiple selection:
``<select multiple="multiple">...</select>``
``<select multiple>...</select>``
``RadioSelect``
~~~~~~~~~~~~~~~

View File

@ -251,6 +251,10 @@ Miscellaneous
* ``allowed_hosts`` is now a required argument of private API
``django.utils.http.is_safe_url()``.
* The ``multiple`` attribute rendered by the
:class:`~django.forms.SelectMultiple` widget now uses HTML5 boolean syntax
rather than XHTML's ``mulitple="multiple"``.
.. _deprecated-features-2.1:
Features deprecated in 2.1

View File

@ -255,7 +255,7 @@ class FilteredSelectMultipleWidgetTest(SimpleTestCase):
w = widgets.FilteredSelectMultiple('test\\', False)
self.assertHTMLEqual(
w.render('test', 'test'),
'<select multiple="multiple" name="test" class="selectfilter" '
'<select multiple name="test" class="selectfilter" '
'data-field-name="test\\" data-is-stacked="0">\n</select>'
)
@ -264,7 +264,7 @@ class FilteredSelectMultipleWidgetTest(SimpleTestCase):
w = widgets.FilteredSelectMultiple('test\\', True)
self.assertHTMLEqual(
w.render('test', 'test'),
'<select multiple="multiple" name="test" class="selectfilterstacked" '
'<select multiple name="test" class="selectfilterstacked" '
'data-field-name="test\\" data-is-stacked="1">\n</select>'
)

View File

@ -129,7 +129,7 @@ class MultiValueFieldTest(SimpleTestCase):
"""
<tr><th><label for="id_field1_0">Field1:</label></th>
<td><input type="text" name="field1_0" id="id_field1_0" required />
<select multiple="multiple" name="field1_1" id="id_field1_1" required>
<select multiple name="field1_1" id="id_field1_1" required>
<option value="J">John</option>
<option value="P">Paul</option>
<option value="G">George</option>
@ -152,7 +152,7 @@ class MultiValueFieldTest(SimpleTestCase):
"""
<tr><th><label for="id_field1_0">Field1:</label></th>
<td><input type="text" name="field1_0" value="some text" id="id_field1_0" required />
<select multiple="multiple" name="field1_1" id="id_field1_1" required>
<select multiple name="field1_1" id="id_field1_1" required>
<option value="J" selected>John</option>
<option value="P" selected>Paul</option>
<option value="G">George</option>

View File

@ -760,7 +760,7 @@ Java</label></li>
composers = MultipleChoiceField()
f = SongForm(auto_id=False)
self.assertHTMLEqual(str(f['composers']), """<select multiple="multiple" name="composers" required>
self.assertHTMLEqual(str(f['composers']), """<select multiple name="composers" required>
</select>""")
class SongForm(Form):
@ -768,13 +768,13 @@ Java</label></li>
composers = MultipleChoiceField(choices=[('J', 'John Lennon'), ('P', 'Paul McCartney')])
f = SongForm(auto_id=False)
self.assertHTMLEqual(str(f['composers']), """<select multiple="multiple" name="composers" required>
self.assertHTMLEqual(str(f['composers']), """<select multiple name="composers" required>
<option value="J">John Lennon</option>
<option value="P">Paul McCartney</option>
</select>""")
f = SongForm({'name': 'Yesterday', 'composers': ['P']}, auto_id=False)
self.assertHTMLEqual(str(f['name']), '<input type="text" name="name" value="Yesterday" required />')
self.assertHTMLEqual(str(f['composers']), """<select multiple="multiple" name="composers" required>
self.assertHTMLEqual(str(f['composers']), """<select multiple name="composers" required>
<option value="J">John Lennon</option>
<option value="P" selected>Paul McCartney</option>
</select>""")
@ -1865,7 +1865,7 @@ Password: <input type="password" name="password" required /></li>"""
p.as_ul(),
"""<li>Username: <input type="text" name="username" value="django" maxlength="10" required /></li>
<li>Password: <input type="password" name="password" required /></li>
<li>Options: <select multiple="multiple" name="options" required>
<li>Options: <select multiple name="options" required>
<option value="f" selected>foo</option>
<option value="b" selected>bar</option>
<option value="w">whiz</option>
@ -1881,7 +1881,7 @@ Username: <input type="text" name="username" maxlength="10" required /></li>
<li><ul class="errorlist"><li>This field is required.</li></ul>
Password: <input type="password" name="password" required /></li>
<li><ul class="errorlist"><li>This field is required.</li></ul>
Options: <select multiple="multiple" name="options" required>
Options: <select multiple name="options" required>
<option value="f">foo</option>
<option value="b">bar</option>
<option value="w">whiz</option>
@ -1895,7 +1895,7 @@ Options: <select multiple="multiple" name="options" required>
<li><ul class="errorlist"><li>This field is required.</li></ul>
Password: <input type="password" name="password" required /></li>
<li><ul class="errorlist"><li>This field is required.</li></ul>
Options: <select multiple="multiple" name="options" required>
Options: <select multiple name="options" required>
<option value="f">foo</option>
<option value="b">bar</option>
<option value="w">whiz</option>
@ -1909,7 +1909,7 @@ Options: <select multiple="multiple" name="options" required>
"""<li>Username: <input type="text" name="username" value="foo" maxlength="10" required /></li>
<li><ul class="errorlist"><li>This field is required.</li></ul>
Password: <input type="password" name="password" required /></li>
<li>Options: <select multiple="multiple" name="options" required>
<li>Options: <select multiple name="options" required>
<option value="f" selected>foo</option>
<option value="b" selected>bar</option>
<option value="w">whiz</option>
@ -1938,7 +1938,7 @@ Password: <input type="password" name="password" required /></li>
p.as_ul(),
"""<li>Username: <input type="text" name="username" value="django" maxlength="10" required /></li>
<li>Password: <input type="password" name="password" required /></li>
<li>Options: <select multiple="multiple" name="options" required>
<li>Options: <select multiple name="options" required>
<option value="f">foo</option>
<option value="b" selected>bar</option>
<option value="w" selected>whiz</option>
@ -1949,7 +1949,7 @@ Password: <input type="password" name="password" required /></li>
p.as_ul(),
"""<li>Username: <input type="text" name="username" value="stephane" maxlength="10" required /></li>
<li>Password: <input type="password" name="password" required /></li>
<li>Options: <select multiple="multiple" name="options" required>
<li>Options: <select multiple name="options" required>
<option value="f" selected>foo</option>
<option value="b" selected>bar</option>
<option value="w">whiz</option>

View File

@ -116,13 +116,13 @@ class ModelFormCallableModelDefault(TestCase):
<option value="3">ChoiceOption 3</option>
</select><input type="hidden" name="initial-choice_int" value="1" id="initial-id_choice_int" /></p>
<p><label for="id_multi_choice">Multi choice:</label>
<select multiple="multiple" name="multi_choice" id="id_multi_choice" required>
<select multiple name="multi_choice" id="id_multi_choice" required>
<option value="1" selected>ChoiceOption 1</option>
<option value="2">ChoiceOption 2</option>
<option value="3">ChoiceOption 3</option>
</select><input type="hidden" name="initial-multi_choice" value="1" id="initial-id_multi_choice_0" /></p>
<p><label for="id_multi_choice_int">Multi choice int:</label>
<select multiple="multiple" name="multi_choice_int" id="id_multi_choice_int" required>
<select multiple name="multi_choice_int" id="id_multi_choice_int" required>
<option value="1" selected>ChoiceOption 1</option>
<option value="2">ChoiceOption 2</option>
<option value="3">ChoiceOption 3</option>
@ -152,14 +152,14 @@ class ModelFormCallableModelDefault(TestCase):
<option value="3">ChoiceOption 3</option>
</select><input type="hidden" name="initial-choice_int" value="2" id="initial-id_choice_int" /></p>
<p><label for="id_multi_choice">Multi choice:</label>
<select multiple="multiple" name="multi_choice" id="id_multi_choice" required>
<select multiple name="multi_choice" id="id_multi_choice" required>
<option value="1">ChoiceOption 1</option>
<option value="2" selected>ChoiceOption 2</option>
<option value="3" selected>ChoiceOption 3</option>
</select><input type="hidden" name="initial-multi_choice" value="2" id="initial-id_multi_choice_0" />
<input type="hidden" name="initial-multi_choice" value="3" id="initial-id_multi_choice_1" /></p>
<p><label for="id_multi_choice_int">Multi choice int:</label>
<select multiple="multiple" name="multi_choice_int" id="id_multi_choice_int" required>
<select multiple name="multi_choice_int" id="id_multi_choice_int" required>
<option value="1">ChoiceOption 1</option>
<option value="2" selected>ChoiceOption 2</option>
<option value="3" selected>ChoiceOption 3</option>

View File

@ -155,7 +155,7 @@ class MultiWidgetTest(WidgetTest):
self.check_html(widget, 'name', 'some text,JP,2007-04-25 06:24:00', html=(
"""
<input type="text" name="name_0" value="some text" />
<select multiple="multiple" name="name_1">
<select multiple name="name_1">
<option value="J" selected>John</option>
<option value="P" selected>Paul</option>
<option value="G">George</option>

View File

@ -15,7 +15,7 @@ class SelectMultipleTest(WidgetTest):
def test_render_selected(self):
self.check_html(self.widget(choices=self.beatles), 'beatles', ['J'], html=(
"""<select multiple="multiple" name="beatles">
"""<select multiple name="beatles">
<option value="J" selected>John</option>
<option value="P">Paul</option>
<option value="G">George</option>
@ -25,7 +25,7 @@ class SelectMultipleTest(WidgetTest):
def test_render_multiple_selected(self):
self.check_html(self.widget(choices=self.beatles), 'beatles', ['J', 'P'], html=(
"""<select multiple="multiple" name="beatles">
"""<select multiple name="beatles">
<option value="J" selected>John</option>
<option value="P" selected>Paul</option>
<option value="G">George</option>
@ -38,7 +38,7 @@ class SelectMultipleTest(WidgetTest):
If the value is None, none of the options are selected.
"""
self.check_html(self.widget(choices=self.beatles), 'beatles', None, html=(
"""<select multiple="multiple" name="beatles">
"""<select multiple name="beatles">
<option value="J">John</option>
<option value="P">Paul</option>
<option value="G">George</option>
@ -52,7 +52,7 @@ class SelectMultipleTest(WidgetTest):
of the options are selected.
"""
self.check_html(self.widget(choices=self.beatles), 'beatles', ['John'], html=(
"""<select multiple="multiple" name="beatles">
"""<select multiple name="beatles">
<option value="J">John</option>
<option value="P">Paul</option>
<option value="G">George</option>
@ -65,7 +65,7 @@ class SelectMultipleTest(WidgetTest):
Multiple options with the same value can be selected (#8103).
"""
self.check_html(self.widget(choices=self.numeric_choices), 'choices', ['0'], html=(
"""<select multiple="multiple" name="choices">
"""<select multiple name="choices">
<option value="0" selected>0</option>
<option value="1">1</option>
<option value="2">2</option>
@ -80,7 +80,7 @@ class SelectMultipleTest(WidgetTest):
ones are selected.
"""
self.check_html(self.widget(choices=self.beatles), 'beatles', ['J', 'G', 'foo'], html=(
"""<select multiple="multiple" name="beatles">
"""<select multiple name="beatles">
<option value="J" selected>John</option>
<option value="P">Paul</option>
<option value="G" selected>George</option>
@ -92,7 +92,7 @@ class SelectMultipleTest(WidgetTest):
choices = [('1', '1'), ('2', '2'), ('3', '3')]
self.check_html(self.widget(choices=choices), 'nums', [2], html=(
"""<select multiple="multiple" name="nums">
"""<select multiple name="nums">
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
@ -100,7 +100,7 @@ class SelectMultipleTest(WidgetTest):
))
self.check_html(self.widget(choices=choices), 'nums', ['2'], html=(
"""<select multiple="multiple" name="nums">
"""<select multiple name="nums">
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
@ -108,7 +108,7 @@ class SelectMultipleTest(WidgetTest):
))
self.check_html(self.widget(choices=choices), 'nums', [2], html=(
"""<select multiple="multiple" name="nums">
"""<select multiple name="nums">
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
@ -121,7 +121,7 @@ class SelectMultipleTest(WidgetTest):
('Group "1"', (('inner1', 'Inner 1'), ('inner2', 'Inner 2'))),
))
self.check_html(widget, 'nestchoice', ['outer1', 'inner2'], html=(
"""<select multiple="multiple" name="nestchoice">
"""<select multiple name="nestchoice">
<option value="outer1" selected>Outer 1</option>
<optgroup label="Group &quot;1&quot;">
<option value="inner1">Inner 1</option>

View File

@ -1168,7 +1168,7 @@ class ModelFormBasicTests(TestCase):
<option value="%s">Mike Royko</option>
</select></li>
<li>Article: <textarea rows="10" cols="40" name="article" required></textarea></li>
<li>Categories: <select multiple="multiple" name="categories">
<li>Categories: <select multiple name="categories">
<option value="%s" selected>Entertainment</option>
<option value="%s" selected>It&#39;s a test</option>
<option value="%s">Third test</option>
@ -1210,7 +1210,7 @@ class ModelFormBasicTests(TestCase):
<option value="%s" selected>Mike Royko</option>
</select></li>
<li>Article: <textarea rows="10" cols="40" name="article" required>Hello.</textarea></li>
<li>Categories: <select multiple="multiple" name="categories">
<li>Categories: <select multiple name="categories">
<option value="%s">Entertainment</option>
<option value="%s">It&#39;s a test</option>
<option value="%s">Third test</option>
@ -1258,7 +1258,7 @@ class ModelFormBasicTests(TestCase):
"""<li><label for="id_headline">Headline:</label>
<input id="id_headline" type="text" name="headline" maxlength="50" required /></li>
<li><label for="id_categories">Categories:</label>
<select multiple="multiple" name="categories" id="id_categories">
<select multiple name="categories" id="id_categories">
<option value="%d" selected>Entertainment</option>
<option value="%d" selected>It&39;s a test</option>
<option value="%d">Third test</option>
@ -1327,7 +1327,7 @@ class ModelFormBasicTests(TestCase):
<option value="%s">Mike Royko</option>
</select></td></tr>
<tr><th>Article:</th><td><textarea rows="10" cols="40" name="article" required></textarea></td></tr>
<tr><th>Categories:</th><td><select multiple="multiple" name="categories">
<tr><th>Categories:</th><td><select multiple name="categories">
<option value="%s">Entertainment</option>
<option value="%s">It&#39;s a test</option>
<option value="%s">Third test</option>
@ -1357,7 +1357,7 @@ class ModelFormBasicTests(TestCase):
<option value="%s" selected>Mike Royko</option>
</select></li>
<li>Article: <textarea rows="10" cols="40" name="article" required>Hello.</textarea></li>
<li>Categories: <select multiple="multiple" name="categories">
<li>Categories: <select multiple name="categories">
<option value="%s" selected>Entertainment</option>
<option value="%s">It&#39;s a test</option>
<option value="%s">Third test</option>
@ -1501,7 +1501,7 @@ class ModelFormBasicTests(TestCase):
<option value="%s">Mike Royko</option>
</select></li>
<li>Article: <textarea rows="10" cols="40" name="article" required></textarea></li>
<li>Categories: <select multiple="multiple" name="categories">
<li>Categories: <select multiple name="categories">
<option value="%s">Entertainment</option>
<option value="%s">It&#39;s a test</option>
<option value="%s">Third test</option>
@ -1527,7 +1527,7 @@ class ModelFormBasicTests(TestCase):
<option value="%s">Mike Royko</option>
</select></li>
<li>Article: <textarea rows="10" cols="40" name="article" required></textarea></li>
<li>Categories: <select multiple="multiple" name="categories">
<li>Categories: <select multiple name="categories">
<option value="%s">Entertainment</option>
<option value="%s">It&#39;s a test</option>
<option value="%s">Third test</option>
@ -2681,7 +2681,7 @@ class OtherModelFormTests(TestCase):
form.as_p(),
"""<p><label for="id_name">Name:</label> <input id="id_name" type="text" name="name" maxlength="50" required /></p>
<p><label for="id_colours">Colours:</label>
<select multiple="multiple" name="colours" id="id_colours" required>
<select multiple name="colours" id="id_colours" required>
<option value="%(blue_pk)s">Blue</option>
</select></p>"""
% {'blue_pk': colour.pk})