diff --git a/deformdemo/__init__.py b/deformdemo/__init__.py index 9dcca57..4bb627f 100644 --- a/deformdemo/__init__.py +++ b/deformdemo/__init__.py @@ -2550,35 +2550,27 @@ class Schema(colander.Schema): @view_config(renderer="templates/form.pt", name="multiple_forms") @demonstrate("Multiple Forms on the Same Page") def multiple_forms(self): - import itertools - # We need to make sure the form field identifiers for the two # forms do not overlap so accessibility features continue to work, # such as focusing the field related to a legend when the # legend is clicked on. - # We do so by creating an ``itertools.count`` object and - # passing that object as the ``counter`` keyword argument to - # the constructor of both forms. As a result, the second - # form's element identifiers will not overlap the first - # form's. - - counter = itertools.count() + # We do so by passing distinct ``formid`` keyword arguments to the + # constructor of both forms. As a result, the form's element identifiers + # will inherit the parent's ``formid`` and will not conflict. + # (Note: alternatively, we could create an ``itertools.count`` object + # and pass that object as the ``counter`` keyword argument.) class Schema1(colander.Schema): name1 = colander.SchemaNode(colander.String()) schema1 = Schema1() - form1 = deform.Form( - schema1, buttons=("submit",), formid="form1", counter=counter - ) + form1 = deform.Form(schema1, buttons=("submit",), formid="form1") class Schema2(colander.Schema): name2 = colander.SchemaNode(colander.String()) schema2 = Schema2() - form2 = deform.Form( - schema2, buttons=("submit",), formid="form2", counter=counter - ) + form2 = deform.Form(schema2, buttons=("submit",), formid="form2") html = [] captured = None diff --git a/deformdemo/test.py b/deformdemo/test.py index 5662655..71018fc 100644 --- a/deformdemo/test.py +++ b/deformdemo/test.py @@ -3498,22 +3498,22 @@ class MultipleFormsTests(Base, unittest.TestCase): def test_render_default(self): self.assertEqual( - findid_view("deformField1").get_attribute("name"), "name1" + findid_view("form1Field1").get_attribute("name"), "name1" ) self.assertEqual( - findid_view("deformField1").get_attribute("value"), "" + findid_view("form1Field1").get_attribute("value"), "" ) - self.assertEqual(findid("deformField3").get_attribute("name"), "name2") - self.assertEqual(findid("deformField3").get_attribute("value"), "") + self.assertEqual(findid("form2Field1").get_attribute("name"), "name2") + self.assertEqual(findid("form2Field1").get_attribute("value"), "") self.assertRaises(NoSuchElementException, findcss, ".is-invalid") def test_submit_first(self): - findid("deformField1").send_keys("hey") + findid("form1Field1").send_keys("hey") findid("form1submit").click() self.assertEqual(eval(findid("captured").text), {"name1": "hey"}) def test_submit_second(self): - findid("deformField3").send_keys("hey") + findid("form2Field2").send_keys("hey") findid("form2submit").click() self.assertEqual(eval(findid("captured").text), {"name2": "hey"})