Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.Problem/Motivation
ARIA 1.1 specifies that the aria-required attribute isn't allowed on an element with role="checkbox"--including an input with a checkbox type. aria-required is allowed on checkboxes role. This was confirmed by Wilco Fiers that aria-required wasn't intended to be allowed on the checkbox role.
Steps to reproduce
1) Add a boolean field to the Article content type.
2) Set the field as required.
3) Inspect the checkbox field in the form page to add a new article and see that the aria-required attribute is set.
| Comment | File | Size | Author |
|---|---|---|---|
| #47 | after--patch--pic.png | 30.52 KB | vikashsoni |
| #47 | Before--patch--pic.png | 12.4 KB | vikashsoni |
| #42 | drupal-n3213473-41.patch | 1.91 KB | damienmckenna |
| #39 | 3213473-39.patch | 1.81 KB | ethant |
| #36 | 3213473-36.patch | 1.77 KB | ethant |
Comments
Comment #2
paulocsComment #3
paulocsComment #5
paulocsComment #6
paulocsPlease not consider patch #5. I'll attach a new one.
Comment #7
paulocsComment #8
paulocsComment #9
guilhermevp commentedPatch works as intended.
Before:
After:
Comment #10
larowlanwe can do this in one line
As this is a bug-fix, we need test-coverage that confirms it is fixed to ensure it stays fixed. I guess
\Drupal\Tests\system\Functional\Form\CheckboxTestwould be a good place to look to add it.Comment #11
gauravvvv commentedRe-rolled patch #7, Attached interdiff for same. Please review.
Comment #12
gauravvvv commentedComment #13
paulocsNeeds tests.
Comment #14
paulocsAdding test only patch and full patch.
Comment #16
marcusvsouza commentedRTBC!
Comment #17
paulocsComment #18
larowlancan we add a positive assert here to.
E.g. assert that there is a single checkbox on the page. otherwise someone could remove the checkbox from that form and this test would happily keep passing, but be redundant
Comment #19
henry.odiete commentedMade modifications to the test to add coverage for if checkbox exist
Comment #20
henry.odiete commentedComment #21
chetanbharambe commentedVerified and tested patch #20.
Patch applied successfully and looks good to me.
Testing Steps:
# Goto: admin/structure/types/manage/article/fields
# Click on Add field
# Select a Boolean from "Add a new field"
# Mention the Label name
# Set the field as required.
# Click on save
# Go: node/add/article
# User will able to see checkbox of Boolean
Expected Results:
# Inspect the checkbox field in the form page to add a new article and see that the
requiredattribute is setActual Results:
# Inspect the checkbox field in the form page to add a new article and see that the
aria-requiredattribute is set.Looks good to me.
Can be a move to RTBC.
Comment #22
larowlanwe could use
here and save some lines, but also ensure that we are adding a positive assert that the checkbox is required. At present, someone could remove the #required attribute from that checkbox and this test would pass.
Also, are there any existing test methods we could use here.
When running a functional test, each new test{Something} adds the setup cost of a new install
Comment #23
paulocsWorking on it
Comment #24
paulocsThanks for the feedback @larowlan. Makes totally sense.
I moved the test to
testFormCheckbox()and rewrite it based on comment #22.Comment #25
guilhermevp commentedMoving to RTBC, after updated changes.
Comment #27
meenakshi_j commentedFixed the #24 fails.
Comment #28
paulocsHi @Meenakshi_j,
why did you re-add a new function to test it?
Comment #22 suggests to add it in another function to avoid waste of time installing a new drupal and patch #24 addresses it.
There is also a
CheckboxTest.php.origin the patch. It shouldn't be there.I'm re-adding patch #24. I suspect this is a random fail.
Comment #29
paulocsSetting back to RTBC.
Comment #30
catchLet's add an inline link to the W3C documentation.
I'm also slightly confused that this isn't allowed, since the 'required checkbox' is a common element on a lot of forms these days (usually for terms and conditions).
Comment #31
ethantHad to reroll patch to apply cleanly to 9.27Incorrect pathing - updated patch in next comment.
Comment #32
ethantComment #33
ethantEdit: added patch 33, but realized approach is incorrect. 32 works.
Comment #34
ethantComment #35
swirt#32 tested and works as desired. Also accounts for request in #30.
I also agree with Catch. It seems odd to not allow the aria role of required on a checkbox as it is a common pattern. I think the issue is that there was no agreement on how the role should behave for multiple checkboxes. And if there is no agreement on the role, it could not be spec'd as how it should behave, so it could not be included as a possible role.
Comment #36
ethantAnother version of patch to remove unnecessary NULL check on checkbox.
Comment #37
paulocsComment #38
swirt#36 works. Unclear what the request is for the change back to "needs work".
Comment #39
ethantForgot to account for "checkboxes." This patch adds.
Comment #40
ethantComment #41
damienmckennaHaving reviewed the latest patch it appears to need to be rerolled, and per the coding standards the "See" line should be written in the format "@see [URL]".
Comment #42
damienmckennaRerolled, and updated the syntax of the "@see" comment.
Comment #43
SomeIntern commentedManually tested the output and can confirm it worked against 9.4. I'm setting this back to RTBC because the patch now applies cleanly.
Comment #45
damienmckennaAs spotted by SomeIntern - is this a duplicate of #3096790: aria-required attribute is redundant when required attribute is present?
Comment #46
ethantGood q, @damienmckenna. It seems to me that https://www.drupal.org/project/drupal/issues/3096790 is recommending that we pull out aria-required, entirely. I think I could get behind this initiative. Per https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Tec...,
Comment #47
vikashsoni commentedApplied patch #18 applied successfully and looks good for me
for ref sharing screenshot.....
Comment #48
swirtJust to note DamienMcKenna's 42 altered EthanT's 39 patch slightly.
#39 excluded checkbox, checkboxes, and fieldset
#42 excluded checkbox, and checkboxes
fieldsets is another one that does not support aria-required. https://www.drupal.org/project/drupal/issues/3205691
Unfortunately both of these issues and related patches touch the same lines and pattern which makes them messy to apply.
I suggest changing from a simple string matching to an in_array pattern where things can be added without calamity. Patch coming.
Comment #49
swirtSuggesting that we close this issue and put our support behind https://www.drupal.org/project/drupal/issues/3096790
Comment #53
xjmClosing as a duplicate of #3096790: aria-required attribute is redundant when required attribute is present.