From 9bdb0a388a0512e54579143ed9b292dc47083f4f Mon Sep 17 00:00:00 2001 From: Andrew Macpherson Date: Sun, 26 Aug 2018 06:50:03 +0100 Subject: [PATCH] Check for submit buttons outside of form, associated using form attribute. Resolves #226. --- .../Sniffs/Principle3/Guideline3_2/3_2_2.js | 22 +++++++++++++++++++ Tests/WCAG2/3_2_2_Form_Input.html | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/Standards/WCAG2AAA/Sniffs/Principle3/Guideline3_2/3_2_2.js b/Standards/WCAG2AAA/Sniffs/Principle3/Guideline3_2/3_2_2.js index 201e0fe0..3531c014 100644 --- a/Standards/WCAG2AAA/Sniffs/Principle3/Guideline3_2/3_2_2.js +++ b/Standards/WCAG2AAA/Sniffs/Principle3/Guideline3_2/3_2_2.js @@ -65,6 +65,28 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle3_Guideline3_2_3_2_2 = { } }//end if + if (ok === false) { + // Look for buttons with form attributes, outside of the form. + if (form.id) { + var externalButtons = document.querySelectorAll('button[form], input[form][type=submit], input[form][type=image]'); + externalButtons.forEach( + function(el) { + // Check they aren't reset buttons, or normal buttons. + switch (el.getAttribute('type')) { + case 'reset': + case 'button': + return; + } + + // Confirm they are associated with the form. + if (el.attributes['form'].value === form.id) { + ok = true; + } + } + ); + } + } + if (ok === false) { HTMLCS.addMessage( HTMLCS.ERROR, diff --git a/Tests/WCAG2/3_2_2_Form_Input.html b/Tests/WCAG2/3_2_2_Form_Input.html index 4c20375e..43c5df96 100644 --- a/Tests/WCAG2/3_2_2_Form_Input.html +++ b/Tests/WCAG2/3_2_2_Form_Input.html @@ -7,6 +7,7 @@ Standard: WCAG2AAA Assert: Error *.H32.2 on #missingSubmit Assert: No Error *.H32.2 on #defaultSubmitType +Assert: No Error *.H32.2 on #externalSubmitType --> @@ -17,5 +18,8 @@ +
+ +