Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #19874: Apply id attribute to the outer <ul> of CheckboxSelectM…

…ultiple
  • Loading branch information...
commit 844fbc85c1d419ed7ecbb7208bd392c1770ea72d 1 parent 3f05c70
Baptiste Mispelon authored April 07, 2013 claudep committed April 13, 2013
3  django/forms/widgets.py
@@ -690,7 +690,8 @@ def render(self, name, value, attrs=None, choices=()):
690 690
         if value is None: value = []
691 691
         final_attrs = self.build_attrs(attrs, name=name)
692 692
         id_ = final_attrs.get('id', None)
693  
-        output = ['<ul>']
  693
+        start_tag = format_html('<ul id="{0}">', id_) if id_ else '<ul>'
  694
+        output = [start_tag]
694 695
         # Normalize to strings
695 696
         str_values = set([force_text(v) for v in value])
696 697
         for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
5  docs/ref/forms/widgets.txt
@@ -648,6 +648,11 @@ Selector and checkbox widgets
648 648
           ...
649 649
         </ul>
650 650
 
  651
+.. versionchanged:: 1.6
  652
+
  653
+The outer ``<ul>`` container will now receive the ``id`` attribute defined on
  654
+the widget.
  655
+
651 656
 .. _file-upload-widgets:
652 657
 
653 658
 File upload widgets
2  tests/forms_tests/tests/test_forms.py
@@ -533,7 +533,7 @@ class SongForm(Form):
533 533
             composers = MultipleChoiceField(choices=[('J', 'John Lennon'), ('P', 'Paul McCartney')], widget=CheckboxSelectMultiple)
534 534
 
535 535
         f = SongForm(auto_id='%s_id')
536  
-        self.assertHTMLEqual(str(f['composers']), """<ul>
  536
+        self.assertHTMLEqual(str(f['composers']), """<ul id="composers_id">
537 537
 <li><label for="composers_id_0"><input type="checkbox" name="composers" value="J" id="composers_id_0" /> John Lennon</label></li>
538 538
 <li><label for="composers_id_1"><input type="checkbox" name="composers" value="P" id="composers_id_1" /> Paul McCartney</label></li>
539 539
 </ul>""")
4  tests/forms_tests/tests/test_widgets.py
@@ -804,14 +804,14 @@ def get_choices():
804 804
         self.assertHTMLEqual(w.render('nums', ['ŠĐĆŽćžšđ'], choices=[('ŠĐĆŽćžšđ', 'ŠĐabcĆŽćžšđ'), ('ćžšđ', 'abcćžšđ')]), '<ul>\n<li><label><input type="checkbox" name="nums" value="1" /> 1</label></li>\n<li><label><input type="checkbox" name="nums" value="2" /> 2</label></li>\n<li><label><input type="checkbox" name="nums" value="3" /> 3</label></li>\n<li><label><input checked="checked" type="checkbox" name="nums" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" /> \u0160\u0110abc\u0106\u017d\u0107\u017e\u0161\u0111</label></li>\n<li><label><input type="checkbox" name="nums" value="\u0107\u017e\u0161\u0111" /> abc\u0107\u017e\u0161\u0111</label></li>\n</ul>')
805 805
 
806 806
         # Each input gets a separate ID
807  
-        self.assertHTMLEqual(CheckboxSelectMultiple().render('letters', list('ac'), choices=zip(list('abc'), list('ABC')), attrs={'id': 'abc'}), """<ul>
  807
+        self.assertHTMLEqual(CheckboxSelectMultiple().render('letters', list('ac'), choices=zip(list('abc'), list('ABC')), attrs={'id': 'abc'}), """<ul id="abc">
808 808
 <li><label for="abc_0"><input checked="checked" type="checkbox" name="letters" value="a" id="abc_0" /> A</label></li>
809 809
 <li><label for="abc_1"><input type="checkbox" name="letters" value="b" id="abc_1" /> B</label></li>
810 810
 <li><label for="abc_2"><input checked="checked" type="checkbox" name="letters" value="c" id="abc_2" /> C</label></li>
811 811
 </ul>""")
812 812
 
813 813
         # Each input gets a separate ID when the ID is passed to the constructor
814  
-        self.assertHTMLEqual(CheckboxSelectMultiple(attrs={'id': 'abc'}).render('letters', list('ac'), choices=zip(list('abc'), list('ABC'))), """<ul>
  814
+        self.assertHTMLEqual(CheckboxSelectMultiple(attrs={'id': 'abc'}).render('letters', list('ac'), choices=zip(list('abc'), list('ABC'))), """<ul id="abc">
815 815
 <li><label for="abc_0"><input checked="checked" type="checkbox" name="letters" value="a" id="abc_0" /> A</label></li>
816 816
 <li><label for="abc_1"><input type="checkbox" name="letters" value="b" id="abc_1" /> B</label></li>
817 817
 <li><label for="abc_2"><input checked="checked" type="checkbox" name="letters" value="c" id="abc_2" /> C</label></li>

0 notes on commit 844fbc8

Please sign in to comment.
Something went wrong with that request. Please try again.