Skip to content

Commit 9bdb0a3

Browse files
committed
Check for submit buttons outside of form, associated using form attribute.
Resolves #226.
1 parent 4531ae4 commit 9bdb0a3

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

Standards/WCAG2AAA/Sniffs/Principle3/Guideline3_2/3_2_2.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,28 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle3_Guideline3_2_3_2_2 = {
6565
}
6666
}//end if
6767

68+
if (ok === false) {
69+
// Look for buttons with form attributes, outside of the form.
70+
if (form.id) {
71+
var externalButtons = document.querySelectorAll('button[form], input[form][type=submit], input[form][type=image]');
72+
externalButtons.forEach(
73+
function(el) {
74+
// Check they aren't reset buttons, or normal buttons.
75+
switch (el.getAttribute('type')) {
76+
case 'reset':
77+
case 'button':
78+
return;
79+
}
80+
81+
// Confirm they are associated with the form.
82+
if (el.attributes['form'].value === form.id) {
83+
ok = true;
84+
}
85+
}
86+
);
87+
}
88+
}
89+
6890
if (ok === false) {
6991
HTMLCS.addMessage(
7092
HTMLCS.ERROR,

Tests/WCAG2/3_2_2_Form_Input.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Standard: WCAG2AAA
88
Assert: Error *.H32.2 on #missingSubmit
99
Assert: No Error *.H32.2 on #defaultSubmitType
10+
Assert: No Error *.H32.2 on #externalSubmitType
1011
-->
1112
</head>
1213
<body>
@@ -17,5 +18,8 @@
1718
<button>Submit</button>
1819
</form>
1920

21+
<form id="externalSubmitType"></form>
22+
<button form="externalSubmitType">Submit</button>
23+
2024
</body>
2125
</html>

0 commit comments

Comments
 (0)