Ticket #27487: #27487.diff
File #27487.diff, 26.7 KB (added by , 8 years ago) |
---|
-
django/contrib/admin/static/admin/css/widgets.css
diff --git a/django/contrib/admin/static/admin/css/widgets.css b/django/contrib/admin/static/admin/css/widgets.css index d3bd67a..491b18b 100644
a b ul.timelist, .timelist li { 546 546 overflow: hidden; /* clear floated contents */ 547 547 } 548 548 549 .related-widget-wrapper .empty-choice { 550 display: none; 551 } 552 549 553 .related-widget-wrapper-link { 550 554 opacity: 0.3; 551 555 } -
django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
diff --git a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js index 3fb1e52..5f9134f 100644
a b 87 87 elem.value = newId; 88 88 } 89 89 } 90 else if (elemName === 'UL') { 91 // For this case the result won't be appended to a simple html input field, we have a 92 // list (<ul></ul>) and we need to append a new item. An empty item is expected as the 93 // first item of the list, with the format specified. Finally, the empty item will be 94 // used as template in order to replace on it the new information. 95 if (elem.firstChild.className.includes('empty-choice')) { 96 var itemTemplate = elem.firstChild.outerHTML, // Get template html string 97 inputIdRegExp = new RegExp(elem.id + '_-1', 'g'), // RegExp to replace the input field Id 98 inputId = elem.id + '_' + (elem.children.length - 1); // New input Id 99 100 itemTemplate = itemTemplate.replace(/empty-choice/g, ''); // Remove 'empty-choice' class 101 itemTemplate = itemTemplate.replace(inputIdRegExp, inputId); // Replace the input Id 102 itemTemplate = itemTemplate.replace('value="#"', 'value="' + newId + '"'); // Replace input value 103 itemTemplate = itemTemplate.replace('--EMPTY LABEL--', newRepr); // Replace label value 104 // append new item to the list 105 elem.innerHTML = elem.innerHTML + itemTemplate; 106 } 107 } 90 108 // Trigger a change event to update related links if required. 91 109 $(elem).trigger('change'); 92 110 } else { -
django/forms/widgets.py
diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 7c7e2c9..f75b27f 100644
a b class CheckboxChoiceInput(ChoiceInput): 701 701 @python_2_unicode_compatible 702 702 class ChoiceFieldRenderer(object): 703 703 """ 704 An object used by RadioSelect to enable customization of radiowidgets.704 An object used by RadioSelect and CheckboxSelectMultiple to enable customization of widgets. 705 705 """ 706 706 707 707 choice_input_class = None 708 708 outer_html = '<ul{id_attr}>{content}</ul>' 709 inner_html = '<li >{choice_value}{sub_widgets}</li>'709 inner_html = '<li{class_attr}>{choice_value}{sub_widgets}</li>' 710 710 711 711 def __init__(self, name, value, attrs, choices): 712 712 self.name = name … … class ChoiceFieldRenderer(object): 729 729 Outputs a <ul> for this set of choice fields. 730 730 If an id was given to the field, it is applied to the <ul> (each 731 731 item in the list will get an id of `$id_$i`). 732 The first item of the list will be an empty item. 732 733 """ 733 734 id_ = self.attrs.get('id') 734 735 output = [] 736 737 def append_inner_item_choice(item_choice, index, class_attr=""): 738 w = self.choice_input_class(self.name, self.value, self.attrs.copy(), item_choice, index) 739 output.append( 740 format_html(self.inner_html, class_attr=class_attr, choice_value=force_text(w), sub_widgets='') 741 ) 742 743 # append empty item choice 744 append_inner_item_choice( 745 ('#', '--EMPTY LABEL--'), # empty choice 746 -1, # index 747 format_html(' class="{}"', 'empty-choice') # classes for empty item choice 748 ) 749 735 750 for i, choice in enumerate(self.choices): 736 751 choice_value, choice_label = choice 737 752 if isinstance(choice_label, (tuple, list)): … … class ChoiceFieldRenderer(object): 746 761 ) 747 762 sub_ul_renderer.choice_input_class = self.choice_input_class 748 763 output.append(format_html( 749 self.inner_html, c hoice_value=choice_value,764 self.inner_html, class_attr='', choice_value=choice_value, 750 765 sub_widgets=sub_ul_renderer.render(), 751 766 )) 752 767 else: 753 w = self.choice_input_class(self.name, self.value, self.attrs.copy(),choice, i)754 output.append(format_html(self.inner_html, choice_value=force_text(w), sub_widgets='')) 768 append_inner_item_choice(choice, i) 769 755 770 return format_html( 756 771 self.outer_html, 757 772 id_attr=format_html(' id="{}"', id_) if id_ else '', -
js_tests/admin/RelatedObjectLookups.test.js
diff --git a/js_tests/admin/RelatedObjectLookups.test.js b/js_tests/admin/RelatedObjectLookups.test.js index 83071ed..3877a50 100644
a b 3 3 /* eslint global-strict: 0, strict: 0 */ 4 4 'use strict'; 5 5 6 module('admin.RelatedObjectLookups'); 6 module('admin.RelatedObjectLookups', { 7 setup: function() { 8 this.win = {name: 'id_teacher', close: function() {}}; 9 } 10 }); 7 11 8 12 test('id_to_windowname', function(assert) { 9 13 assert.equal(id_to_windowname('.test'), '__dot__test'); … … test('windowname_to_id', function(assert) { 14 18 assert.equal(windowname_to_id('__dot__test'), '.test'); 15 19 assert.equal(windowname_to_id('misc__dash__test'), 'misc-test'); 16 20 }); 21 22 test('dismissAddRelatedObjectPopup/Select', function(assert) { 23 var $ = django.jQuery; 24 $('<div class="related-widget-wrapper"></div>').appendTo('#qunit-fixture'); 25 $('<select id="id_teacher" name="teacher"></select>').appendTo('div.related-widget-wrapper'); 26 $('<option value="" selected="">---------</option>').appendTo('#id_teacher'); 27 28 dismissAddRelatedObjectPopup(this.win, '1', 'Alex'); 29 assert.equal($('#id_teacher').find('option').length, 2); 30 assert.equal($('#id_teacher').find('option').last().text(), 'Alex'); 31 }); 32 33 test('dismissAddRelatedObjectPopup/SelectMultiple', function(assert) { 34 var $ = django.jQuery; 35 $('<div class="related-widget-wrapper"></div>').appendTo('#qunit-fixture'); 36 $('<select multiple="multiple" id="id_teacher" name="teacher"></select>').appendTo('div.related-widget-wrapper'); 37 38 dismissAddRelatedObjectPopup(this.win, '1', 'Alex'); 39 assert.equal($('#id_teacher').find('option').length, 1); 40 assert.equal($('#id_teacher').find('option').first().text(), 'Alex'); 41 42 dismissAddRelatedObjectPopup(this.win, '2', 'Alan'); 43 assert.equal($('#id_teacher').find('option').length, 2); 44 assert.equal($('#id_teacher').find('option').last().text(), 'Alan'); 45 }); 46 47 test('dismissAddRelatedObjectPopup/TextInput', function(assert) { 48 var $ = django.jQuery; 49 $('<div class="related-widget-wrapper"></div>').appendTo('#qunit-fixture'); 50 $('<input id="id_teacher" name="teacher" type="text" value="">').appendTo('div.related-widget-wrapper'); 51 52 dismissAddRelatedObjectPopup(this.win, '1', 'Alex'); 53 assert.equal($('#id_teacher').val(), '1'); 54 55 dismissAddRelatedObjectPopup(this.win, '2', 'Alan'); 56 assert.equal($('#id_teacher').val(), '2'); 57 }); 58 59 test('dismissAddRelatedObjectPopup/TextInput.vManyToManyRawIdAdminField', function(assert) { 60 var $ = django.jQuery; 61 $('<div class="related-widget-wrapper"></div>').appendTo('#qunit-fixture'); 62 $('<input id="id_teacher" name="teacher" type="text" value="" class="vManyToManyRawIdAdminField">').appendTo( 63 'div.related-widget-wrapper' 64 ); 65 66 dismissAddRelatedObjectPopup(this.win, '1', 'Alex'); 67 assert.equal($('#id_teacher').val(), '1'); 68 69 dismissAddRelatedObjectPopup(this.win, '2', 'Alan'); 70 assert.equal($('#id_teacher').val(), '1,2'); 71 }); 72 73 test('dismissAddRelatedObjectPopup/CheckboxSelectMultiple', function(assert) { 74 var $ = django.jQuery; 75 $('<div class="related-widget-wrapper"></div>').appendTo('#qunit-fixture'); 76 $('<ul id="id_books"></ul>').appendTo('div.related-widget-wrapper'); 77 $('<li class="empty-choice"></li>').appendTo('#id_books'); 78 $('<label for="id_books_-1"></label>').appendTo('li.empty-choice'); 79 $('li label').html('<input id="id_books_-1" name="books" type="checkbox" value="#">--EMPTY LABEL--'); 80 81 this.win = $.extend(this.win, {name: 'id_books'}); 82 83 // add the first item 84 dismissAddRelatedObjectPopup(this.win, '1', 'Book1'); 85 assert.equal($('#id_books').find('li').length, 2); 86 assert.notOk($('#id_books').find('li').last().hasClass("empty-choice")); 87 assert.equal($('input#id_books_0').length, 1); 88 assert.equal($('input#id_books_0').val(), 1); 89 assert.equal($('#id_books').find('li').last().find('label').text(), 'Book1'); 90 assert.equal($('#id_books').find('input').last()[0].type, "checkbox"); 91 92 // add the other item 93 dismissAddRelatedObjectPopup(this.win, '2', 'Book2'); 94 assert.equal($('#id_books').find('li').length, 3); 95 assert.notOk($('#id_books').find('li').last().hasClass("empty-choice")); 96 assert.equal($('input#id_books_1').length, 1); 97 assert.equal($('input#id_books_1').val(), 2); 98 assert.equal($('#id_books').find('li').last().find('label').text(), 'Book2'); 99 assert.equal($('#id_books').find('input').last()[0].type, "checkbox"); 100 }); 101 102 test('dismissAddRelatedObjectPopup/RadioSelect', function(assert) { 103 var $ = django.jQuery; 104 $('<div class="related-widget-wrapper"></div>').appendTo('#qunit-fixture'); 105 $('<ul id="id_books"></ul>').appendTo('div.related-widget-wrapper'); 106 $('<li class="empty-choice"></li>').appendTo('#id_books'); 107 $('<label for="id_books_-1"></label>').appendTo('li.empty-choice'); 108 $('li label').html('<input id="id_books_-1" name="books" type="radio" value="#">--EMPTY LABEL--'); 109 110 this.win = $.extend(this.win, {name: 'id_books'}); 111 112 // add the first item 113 dismissAddRelatedObjectPopup(this.win, '1', 'Book1'); 114 assert.equal($('#id_books').find('li').length, 2); 115 assert.notOk($('#id_books').find('li').last().hasClass("empty-choice")); 116 assert.equal($('input#id_books_0').length, 1); 117 assert.equal($('input#id_books_0').val(), 1); 118 assert.equal($('#id_books').find('li').last().find('label').text(), 'Book1'); 119 assert.equal($('#id_books').find('input').last()[0].type, "radio"); 120 121 // add the other item 122 dismissAddRelatedObjectPopup(this.win, '2', 'Book2'); 123 assert.equal($('#id_books').find('li').length, 3); 124 assert.notOk($('#id_books').find('li').last().hasClass("empty-choice")); 125 assert.equal($('input#id_books_1').length, 1); 126 assert.equal($('input#id_books_1').val(), 2); 127 assert.equal($('#id_books').find('li').last().find('label').text(), 'Book2'); 128 assert.equal($('#id_books').find('input').last()[0].type, "radio"); 129 }); -
tests/forms_tests/tests/test_forms.py
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 8007ad8..0ec3d3f 100644
a b class FormsTestCase(SimpleTestCase): 584 584 585 585 f = FrameworkForm(auto_id=False) 586 586 self.assertHTMLEqual(str(f['language']), """<ul> 587 <li class="empty-choice"><label><input type="radio" name="language" value="#" required /> --EMPTY LABEL--</label></li> 587 588 <li><label><input type="radio" name="language" value="P" required /> Python</label></li> 588 589 <li><label><input type="radio" name="language" value="J" required /> Java</label></li> 589 590 </ul>""") 590 591 self.assertHTMLEqual(f.as_table(), """<tr><th>Name:</th><td><input type="text" name="name" required /></td></tr> 591 592 <tr><th>Language:</th><td><ul> 593 <li class="empty-choice"><label><input type="radio" name="language" value="#" required /> --EMPTY LABEL--</label></li> 592 594 <li><label><input type="radio" name="language" value="P" required /> Python</label></li> 593 595 <li><label><input type="radio" name="language" value="J" required /> Java</label></li> 594 596 </ul></td></tr>""") 595 597 self.assertHTMLEqual(f.as_ul(), """<li>Name: <input type="text" name="name" required /></li> 596 598 <li>Language: <ul> 599 <li class="empty-choice"><label><input type="radio" name="language" value="#" required /> --EMPTY LABEL--</label></li> 597 600 <li><label><input type="radio" name="language" value="P" required /> Python</label></li> 598 601 <li><label><input type="radio" name="language" value="J" required /> Java</label></li> 599 602 </ul></li>""") … … class FormsTestCase(SimpleTestCase): 605 608 self.assertHTMLEqual( 606 609 str(f['language']), 607 610 """<ul id="id_language"> 611 <li class="empty-choice"><label for="id_language_-1"> 612 <input type="radio" id="id_language_-1" value="#" name="language" required /> --EMPTY LABEL--</label></li> 608 613 <li><label for="id_language_0"><input type="radio" id="id_language_0" value="P" name="language" required /> 609 614 Python</label></li> 610 615 <li><label for="id_language_1"><input type="radio" id="id_language_1" value="J" name="language" required /> … … Java</label></li> 619 624 f.as_table(), 620 625 """<tr><th><label for="id_name">Name:</label></th><td><input type="text" name="name" id="id_name" required /></td></tr> 621 626 <tr><th><label for="id_language_0">Language:</label></th><td><ul id="id_language"> 627 <li class="empty-choice"><label for="id_language_-1"> 628 <input type="radio" id="id_language_-1" value="#" name="language" required />--EMPTY LABEL--</label></li> 622 629 <li><label for="id_language_0"><input type="radio" id="id_language_0" value="P" name="language" required /> 623 630 Python</label></li> 624 631 <li><label for="id_language_1"><input type="radio" id="id_language_1" value="J" name="language" required /> … … Java</label></li> 629 636 f.as_ul(), 630 637 """<li><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" required /></li> 631 638 <li><label for="id_language_0">Language:</label> <ul id="id_language"> 639 <li class="empty-choice"><label for="id_language_-1"> 640 <input type="radio" id="id_language_-1" value="#" name="language" required />--EMPTY LABEL--</label></li> 632 641 <li><label for="id_language_0"><input type="radio" id="id_language_0" value="P" name="language" required /> 633 642 Python</label></li> 634 643 <li><label for="id_language_1"><input type="radio" id="id_language_1" value="J" name="language" required /> … … Java</label></li> 639 648 f.as_p(), 640 649 """<p><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" required /></p> 641 650 <p><label for="id_language_0">Language:</label> <ul id="id_language"> 651 <li class="empty-choice"><label for="id_language_-1"> 652 <input type="radio" id="id_language_-1" value="#" name="language" required />--EMPTY LABEL--</label></li> 642 653 <li><label for="id_language_0"><input type="radio" id="id_language_0" value="P" name="language" required /> 643 654 Python</label></li> 644 655 <li><label for="id_language_1"><input type="radio" id="id_language_1" value="J" name="language" required /> … … Java</label></li> 808 819 809 820 f = SongForm(auto_id=False) 810 821 self.assertHTMLEqual(str(f['composers']), """<ul> 822 <li class="empty-choice"><label><input type="checkbox" name="composers" value="#" /> --EMPTY LABEL--</label></li> 811 823 <li><label><input type="checkbox" name="composers" value="J" /> John Lennon</label></li> 812 824 <li><label><input type="checkbox" name="composers" value="P" /> Paul McCartney</label></li> 813 825 </ul>""") 814 826 f = SongForm({'composers': ['J']}, auto_id=False) 815 827 self.assertHTMLEqual(str(f['composers']), """<ul> 828 <li class="empty-choice"><label><input type="checkbox" name="composers" value="#" /> --EMPTY LABEL--</label></li> 816 829 <li><label><input checked type="checkbox" name="composers" value="J" /> John Lennon</label></li> 817 830 <li><label><input type="checkbox" name="composers" value="P" /> Paul McCartney</label></li> 818 831 </ul>""") 819 832 f = SongForm({'composers': ['J', 'P']}, auto_id=False) 820 833 self.assertHTMLEqual(str(f['composers']), """<ul> 834 <li class="empty-choice"><label><input type="checkbox" name="composers" value="#" /> --EMPTY LABEL--</label></li> 821 835 <li><label><input checked type="checkbox" name="composers" value="J" /> John Lennon</label></li> 822 836 <li><label><input checked type="checkbox" name="composers" value="P" /> Paul McCartney</label></li> 823 837 </ul>""") … … Java</label></li> 843 857 self.assertHTMLEqual( 844 858 str(f['composers']), 845 859 """<ul id="composers_id"> 860 <li class="empty-choice"><label for="composers_id_-1"> 861 <input type="checkbox" name="composers" value="#" id="composers_id_-1" /> --EMPTY LABEL--</label></li> 846 862 <li><label for="composers_id_0"> 847 863 <input type="checkbox" name="composers" value="J" id="composers_id_0" /> John Lennon</label></li> 848 864 <li><label for="composers_id_1"> -
tests/forms_tests/tests/test_i18n.py
diff --git a/tests/forms_tests/tests/test_i18n.py b/tests/forms_tests/tests/test_i18n.py index 56225e0..956f4ec 100644
a b class FormsI18nTests(SimpleTestCase): 60 60 f.as_p(), 61 61 '<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label>' 62 62 '<ul id="id_somechoice">\n' 63 '<li class="empty-choice"><label for="id_somechoice_-1">' 64 '<input type="radio" id="id_somechoice_-1" value="#" name="somechoice" required /> ' 65 '--EMPTY LABEL--</label></li>\n' 63 66 '<li><label for="id_somechoice_0">' 64 67 '<input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" required /> ' 65 68 'En tied\xe4</label></li>\n' … … class FormsI18nTests(SimpleTestCase): 79 82 '\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c' 80 83 '\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul>\n' 81 84 '<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label>' 82 ' <ul id="id_somechoice">\n<li><label for="id_somechoice_0">' 85 ' <ul id="id_somechoice">\n<li class="empty-choice"><label for="id_somechoice_-1">' 86 '<input type="radio" id="id_somechoice_-1" value="#" name="somechoice" required /> ' 87 '--EMPTY LABEL--</label></li>\n' 88 '<li><label for="id_somechoice_0">' 83 89 '<input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" required /> ' 84 90 'En tied\xe4</label></li>\n' 85 91 '<li><label for="id_somechoice_1">' -
tests/forms_tests/tests/test_widgets.py
diff --git a/tests/forms_tests/tests/test_widgets.py b/tests/forms_tests/tests/test_widgets.py index 7ea2b35..b33248d 100644
a b beatle J R Ringo False""") 118 118 self.assertHTMLEqual( 119 119 output, 120 120 """<div id="bar"> 121 <p><label for="bar_-1"><input type="radio" id="bar_-1" value="#" name="beatle" /> --EMPTY LABEL--</label></p> 121 122 <p><label for="bar_0"><input checked type="radio" id="bar_0" value="J" name="beatle" /> John</label></p> 122 123 <p><label for="bar_1"><input type="radio" id="bar_1" value="P" name="beatle" /> Paul</label></p> 123 124 <p><label for="bar_2"><input type="radio" id="bar_2" value="G" name="beatle" /> George</label></p> -
tests/forms_tests/widget_tests/test_checkboxselectmultiple.py
diff --git a/tests/forms_tests/widget_tests/test_checkboxselectmultiple.py b/tests/forms_tests/widget_tests/test_checkboxselectmultiple.py index 27e8705..07cef1f 100644
a b class CheckboxSelectMultipleTest(WidgetTest): 9 9 def test_render_value(self): 10 10 self.check_html(self.widget(choices=self.beatles), 'beatles', ['J'], html=( 11 11 """<ul> 12 <li class="empty-choice"> 13 <label><input type="checkbox" name="beatles" value="#" /> --EMPTY LABEL--</label> 14 </li> 12 15 <li><label><input checked type="checkbox" name="beatles" value="J" /> John</label></li> 13 16 <li><label><input type="checkbox" name="beatles" value="P" /> Paul</label></li> 14 17 <li><label><input type="checkbox" name="beatles" value="G" /> George</label></li> … … class CheckboxSelectMultipleTest(WidgetTest): 19 22 def test_render_value_multiple(self): 20 23 self.check_html(self.widget(choices=self.beatles), 'beatles', ['J', 'P'], html=( 21 24 """<ul> 25 <li class="empty-choice"> 26 <label><input type="checkbox" name="beatles" value="#" /> --EMPTY LABEL--</label> 27 </li> 22 28 <li><label><input checked type="checkbox" name="beatles" value="J" /> John</label></li> 23 29 <li><label><input checked type="checkbox" name="beatles" value="P" /> Paul</label></li> 24 30 <li><label><input type="checkbox" name="beatles" value="G" /> George</label></li> … … class CheckboxSelectMultipleTest(WidgetTest): 32 38 """ 33 39 self.check_html(self.widget(choices=self.beatles), 'beatles', None, html=( 34 40 """<ul> 41 <li class="empty-choice"> 42 <label><input type="checkbox" name="beatles" value="#" /> --EMPTY LABEL--</label> 43 </li> 35 44 <li><label><input type="checkbox" name="beatles" value="J" /> John</label></li> 36 45 <li><label><input type="checkbox" name="beatles" value="P" /> Paul</label></li> 37 46 <li><label><input type="checkbox" name="beatles" value="G" /> George</label></li> … … class CheckboxSelectMultipleTest(WidgetTest): 47 56 ) 48 57 html = """ 49 58 <ul id="media"> 59 <li class="empty-choice"> 60 <label for="media_-1"> 61 <input id="media_-1" name="nestchoice" type="checkbox" value="#" /> --EMPTY LABEL-- 62 </label> 63 </li> 50 64 <li> 51 65 <label for="media_0"><input id="media_0" name="nestchoice" type="checkbox" value="unknown" /> Unknown</label> 52 66 </li> 53 67 <li>Audio<ul id="media_1"> 68 <li class="empty-choice"> 69 <label for="media_1_-1"> 70 <input id="media_1_-1" name="nestchoice" type="checkbox" value="#" /> --EMPTY LABEL-- 71 </label> 72 </li> 54 73 <li> 55 74 <label for="media_1_0"> 56 75 <input checked id="media_1_0" name="nestchoice" type="checkbox" value="vinyl" /> Vinyl … … class CheckboxSelectMultipleTest(WidgetTest): 61 80 </li> 62 81 </ul></li> 63 82 <li>Video<ul id="media_2"> 83 <li class="empty-choice"> 84 <label for="media_2_-1"> 85 <input id="media_2_-1" name="nestchoice" type="checkbox" value="#" /> --EMPTY LABEL-- 86 </label> 87 </li> 64 88 <li> 65 89 <label for="media_2_0"><input id="media_2_0" name="nestchoice" type="checkbox" value="vhs" /> VHS</label> 66 90 </li> … … class CheckboxSelectMultipleTest(WidgetTest): 84 108 choices = [('a', 'A'), ('b', 'B'), ('c', 'C')] 85 109 html = """ 86 110 <ul id="abc"> 111 <li class="empty-choice"> 112 <label for="abc_-1"><input type="checkbox" name="letters" value="#" id="abc_-1" /> --EMPTY LABEL--</label> 113 </li> 87 114 <li> 88 115 <label for="abc_0"><input checked type="checkbox" name="letters" value="a" id="abc_0" /> A</label> 89 116 </li> … … class CheckboxSelectMultipleTest(WidgetTest): 102 129 widget = CheckboxSelectMultiple(attrs={'id': 'abc'}, choices=[('a', 'A'), ('b', 'B'), ('c', 'C')]) 103 130 html = """ 104 131 <ul id="abc"> 132 <li class="empty-choice"> 133 <label for="abc_-1"><input type="checkbox" name="letters" value="#" id="abc_-1" /> --EMPTY LABEL--</label> 134 </li> 105 135 <li> 106 136 <label for="abc_0"><input checked type="checkbox" name="letters" value="a" id="abc_0" /> A</label> 107 137 </li> -
tests/forms_tests/widget_tests/test_radioselect.py
diff --git a/tests/forms_tests/widget_tests/test_radioselect.py b/tests/forms_tests/widget_tests/test_radioselect.py index fea26ce..c44cb4c 100644
a b class RadioSelectTest(WidgetTest): 9 9 def test_render(self): 10 10 self.check_html(self.widget(choices=self.beatles), 'beatle', 'J', html=( 11 11 """<ul> 12 <li class="empty-choice"><label><input type="radio" name="beatle" value="#" /> --EMPTY LABEL--</label></li> 12 13 <li><label><input checked type="radio" name="beatle" value="J" /> John</label></li> 13 14 <li><label><input type="radio" name="beatle" value="P" /> Paul</label></li> 14 15 <li><label><input type="radio" name="beatle" value="G" /> George</label></li> … … class RadioSelectTest(WidgetTest): 24 25 ) 25 26 html = """ 26 27 <ul id="media"> 28 <li class="empty-choice"> 29 <label for="media_-1"><input id="media_-1" name="nestchoice" type="radio" value="#" /> --EMPTY LABEL--</label> 30 </li> 27 31 <li> 28 32 <label for="media_0"><input id="media_0" name="nestchoice" type="radio" value="unknown" /> Unknown</label> 29 33 </li> 30 34 <li>Audio<ul id="media_1"> 35 <li class="empty-choice"> 36 <label for="media_1_-1"> 37 <input id="media_1_-1" name="nestchoice" type="radio" value="#" /> --EMPTY LABEL-- 38 </label> 39 </li> 31 40 <li> 32 41 <label for="media_1_0"><input id="media_1_0" name="nestchoice" type="radio" value="vinyl" /> Vinyl</label> 33 42 </li> 34 43 <li><label for="media_1_1"><input id="media_1_1" name="nestchoice" type="radio" value="cd" /> CD</label></li> 35 44 </ul></li> 36 45 <li>Video<ul id="media_2"> 46 <li class="empty-choice"> 47 <label for="media_2_-1"> 48 <input id="media_2_-1" name="nestchoice" type="radio" value="#" /> --EMPTY LABEL-- 49 </label> 50 </li> 37 51 <li><label for="media_2_0"><input id="media_2_0" name="nestchoice" type="radio" value="vhs" /> VHS</label></li> 38 52 <li> 39 53 <label for="media_2_1"> … … class RadioSelectTest(WidgetTest): 56 70 widget = RadioSelect(attrs={'id': 'foo'}, choices=self.beatles) 57 71 html = """ 58 72 <ul id="foo"> 73 <li class="empty-choice"> 74 <label for="foo_-1"><input type="radio" id="foo_-1" value="#" name="beatle" /> --EMPTY LABEL--</label> 75 </li> 59 76 <li> 60 77 <label for="foo_0"><input checked type="radio" id="foo_0" value="J" name="beatle" /> John</label> 61 78 </li> … … class RadioSelectTest(WidgetTest): 73 90 """ 74 91 html = """ 75 92 <ul id="bar"> 93 <li class="empty-choice"> 94 <label for="bar_-1"><input type="radio" id="bar_-1" value="#" name="beatle" /> --EMPTY LABEL--</label> 95 </li> 76 96 <li> 77 97 <label for="bar_0"><input checked type="radio" id="bar_0" value="J" name="beatle" /> John</label> 78 98 </li>