1 description('Test that label.control references the correct form control, or null if there is no associated control.');
3 debug("Find a control that is the first descendent in a label");
4 document.write("<label id='test1'><input id='inputId1'></label>");
5 shouldBe("document.getElementById('test1').control.id", "'inputId1'");
7 debug("Find a control based on a label with valid 'for' attribute");
8 document.write("<label id='test2' for='inputId2'></label><input id='inputId2' type='number'>");
9 shouldBe("document.getElementById('test2').htmlFor", "'inputId2'");
10 shouldBe("document.getElementById('test2').control.type", "'number'");
12 debug("Find a control in p element in label");
13 document.write("<label id='test3'><p><input id='inputId3' type='date'></p></label>");
14 shouldBe("document.getElementById('test3').control.id", "'inputId3'");
16 debug("Find a control in fieldset in label.");
17 debug("Note that filedset is a form control that is not labelable.");
18 document.write("<label id='test4'><fieldset><input id='inputId4'></fieldset></label>");
19 shouldBe("document.getElementById('test4').control.id", "'inputId4'");
21 debug("Find a control in legend in label.");
22 debug("Note that legend is a form control that is not labelable.");
23 document.write("<label id='test5'><legend><input id='inputId5'></legend></label>");
24 shouldBe("document.getElementById('test5').control.id", "'inputId5'");
26 debug("Find a control in optgroup in label.");
27 debug("Note that optgroup is a form control that is not labelable.");
28 document.write("<label id='test6'><optgroup><input id='inputId6'></optgroup></label>");
29 shouldBe("document.getElementById('test6').control.id", "'inputId6'");
31 debug("Find a control in option in label.");
32 debug("Note that option is a form control that is not labelable.");
33 document.write("<label id='test7'><option><input id='inputId7'></option></label>");
34 shouldBe("document.getElementById('test7').control.id", "'inputId7'");
36 debug("Test label with 'for' attribute which is not a valid element id");
37 document.write("<label for='foo' id='test8'><input id='inputId8'></label>");
38 shouldBe("document.getElementById('test8').control", "null");
40 debug("Test label with 'for' attribute which is not a form control");
41 document.write("<label for='divId' id='test9'><input id='inputId9'></label><div id='divId'></div>");
42 shouldBe("document.getElementById('test9').htmlFor", "'divId'");
43 shouldBe("document.getElementById('test9').control", "null");
45 debug("Test label with 'for' attribute which is not a labelable form control - fieldset");
46 document.write("<label for='fsId' id='test10'><input id='inputId10'></label><fieldset id='fsId'></fieldset>");
47 shouldBe("document.getElementById('test10').htmlFor", "'fsId'");
48 shouldBe("document.getElementById('test10').control", "null");
50 debug("Test label with 'for' attribute which is not a labelable form control - legend");
51 document.write("<label for='legendId' id='test11'><input id='inputId11'></label><legend id='legendId'></legend>");
52 shouldBe("document.getElementById('test11').htmlFor", "'legendId'");
53 shouldBe("document.getElementById('test11').control", "null");
55 debug("Test label with 'for' attribute which is not a labelable form control - optgroup");
56 document.write("<label for='optgroupId' id='test12'><input id='inputId12'></label><optgroup id='optgroupId'></optgroup>");
57 shouldBe("document.getElementById('test12').htmlFor", "'optgroupId'");
58 shouldBe("document.getElementById('test12').control", "null");
60 debug("Test label with 'for' attribute which is not a labelable form control - option");
61 document.write("<label for='optionId' id='test13'><input id='inputId13'></label><option id='optionId'></option>");
62 shouldBe("document.getElementById('test13').htmlFor", "'optionId'");
63 shouldBe("document.getElementById('test13').control", "null");