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