summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMatt Johnson <mdj2@pdx.edu>2013-06-04 22:41:49 +0200
committerTim Graham <timograham@gmail.com>2013-08-13 13:23:05 -0400
commit907ef9d0d157c47c66bf265dca93a0bee8664ea3 (patch)
treebf338246ad0a5df58451711270426913830b130b /tests
parentdb682dcc9e028fa40bb4d3efb322fd3191ed1bd2 (diff)
Fixed #20555 -- Make subwidget id attribute available
In `BoundField.__iter__`, the widget's id attribute is now passed to each subwidget. A new id_for_label property was added to ChoiceInput.
Diffstat (limited to 'tests')
-rw-r--r--tests/forms_tests/tests/test_widgets.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/forms_tests/tests/test_widgets.py b/tests/forms_tests/tests/test_widgets.py
index 06ee2d6c53..3f11771d7a 100644
--- a/tests/forms_tests/tests/test_widgets.py
+++ b/tests/forms_tests/tests/test_widgets.py
@@ -833,6 +833,22 @@ beatle J R Ringo False""")
with self.assertRaises(IndexError):
r[42]
+ def test_subwidget(self):
+ # Each subwidget tag gets a separate ID when the widget has an ID specified
+ self.assertHTMLEqual("\n".join([c.tag() for c in CheckboxSelectMultiple(attrs={'id': 'abc'}).subwidgets('letters', list('ac'), choices=zip(list('abc'), list('ABC')))]), """<input checked="checked" type="checkbox" name="letters" value="a" id="abc_0" />
+<input type="checkbox" name="letters" value="b" id="abc_1" />
+<input checked="checked" type="checkbox" name="letters" value="c" id="abc_2" />""")
+
+ # Each subwidget tag does not get an ID if the widget does not have an ID specified
+ self.assertHTMLEqual("\n".join([c.tag() for c in CheckboxSelectMultiple().subwidgets('letters', list('ac'), choices=zip(list('abc'), list('ABC')))]), """<input checked="checked" type="checkbox" name="letters" value="a" />
+<input type="checkbox" name="letters" value="b" />
+<input checked="checked" type="checkbox" name="letters" value="c" />""")
+
+ # The id_for_label property of the subwidget should return the ID that is used on the subwidget's tag
+ self.assertHTMLEqual("\n".join(['<input type="checkbox" name="letters" value="%s" id="%s" />' % (c.choice_value, c.id_for_label) for c in CheckboxSelectMultiple(attrs={'id': 'abc'}).subwidgets('letters', [], choices=zip(list('abc'), list('ABC')))]), """<input type="checkbox" name="letters" value="a" id="abc_0" />
+<input type="checkbox" name="letters" value="b" id="abc_1" />
+<input type="checkbox" name="letters" value="c" id="abc_2" />""")
+
def test_multi(self):
class MyMultiWidget(MultiWidget):
def decompress(self, value):