Skip to content

Commit 610cdf1

Browse files
committed
WCAG2 3.2.2: Fix false positive for buttons without a type attribute.
Fixes Github issue: squizlabs#136. The default for buttons without a type attribute (or an invalid option, reverting to the default) is actually a submit button. Because there's no way to querySelector() elements WITHOUT an attribute, BUTTON elements are now compared as "number of BUTTON elements in total vs. number that have type attribute of 'reset' or 'button'" - the other two possible valid values. BUTTON elements, however, won't be looked for at all if it can be short-circuited by testing of INPUT elements, though (which has to have a type attribute, because the default field type for INPUT is text).
1 parent 358b158 commit 610cdf1

File tree

1 file changed

+23
-4
lines changed
  • Standards/WCAG2AAA/Sniffs/Principle3/Guideline3_2

1 file changed

+23
-4
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,30 @@ var HTMLCS_WCAG2AAA_Sniffs_Principle3_Guideline3_2_3_2_2 = {
4848
*/
4949
checkFormSubmitButton: function(form)
5050
{
51-
// Test for one of the three types of submit buttons.
52-
var submitButton = form.querySelector('input[type=submit], input[type=image], button[type=submit]');
51+
var ok = false;
5352

54-
if (submitButton === null) {
55-
HTMLCS.addMessage(HTMLCS.ERROR, form, 'Form does not contain a submit button (input type="submit", input type="image", or button type="submit").', 'H32.2');
53+
// Test for INPUT-based submit buttons. The type must be specified, as
54+
// the default for INPUT is text.
55+
var inputButtons = form.querySelectorAll('input[type=submit], input[type=image]');
56+
if (inputButtons.length > 0) {
57+
ok = true;
58+
} else {
59+
// Check for BUTTONs that aren't reset buttons, or normal buttons.
60+
// If they're blank or invalid, they are submit buttons.
61+
var buttonButtons = form.querySelectorAll('button');
62+
var nonSubmitButtons = form.querySelectorAll('button[type=reset], button[type=button]');
63+
if (buttonButtons.length > nonSubmitButtons.length) {
64+
ok = true;
65+
}
66+
}//end if
67+
68+
if (ok === false) {
69+
HTMLCS.addMessage(
70+
HTMLCS.ERROR,
71+
form,
72+
'This form does not contain a submit button, which creates issues for those who cannot submit the form using the keyboard. Submit buttons are INPUT elements with type attribute "submit" or "image", or BUTTON elements with type "submit" or omitted/invalid.',
73+
'H32.2'
74+
);
5675
}
5776
}
5877
};

0 commit comments

Comments
 (0)