I'd like to add a semantic relationship between a form's description and the input it is describing.
I thought I should be able to do that by adding the appropriate text to theme_webform_element, however unfortunately it isn't working.
However the aria-described by element keeps getting stripped out of the input form.
By adding the attribute to the element:
$element['#attributes']['aria-describedby'] = $element['#id'] . '-description';
And attaching the ID to the description:
if (!empty($element['#description'])) {
$describedby = (!empty($element['#id'])) ? ' id=' . $element['#id'] . '-description' : '';
$output .= ' <div class="description"' . $describedby . '>' . $element['#description'] . "</div>\n";
} This should work, but it isn't coming through to the webform. I wonder if the aria-describedby is getting filtered out or if I'm just doing something wrong.
It would be really nice though if this were done by default so that people who are filling in complex forms especially get more semantic descriptions.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | webform-aria_describedby-2143191-7-D7.patch | 1.39 KB | liam morland |
Comments
Comment #1
acrazyanimal commentedThe trick here is to do the following in theme_webform_element and theme_element:
But then you also need to use preprocess functions in your theme/module to add in the aria-describedby attribute to the form elements. There are lots, some are webform specific theme functions and others are core:
.... and I'm sure there are plenty more.
Comment #2
acrazyanimal commentedAn example of the output would be the following:
Comment #3
mgiffordVery good, thanks for that detail! It's definitely worth having in a handbook on Drupal.org or on our blog. This just comes out of the box with D8, but this is the first description of how to do it in Drupal 7.
Comment #4
mgifford@quicksketch - what do you think of bringing this into the 4.x branch?
Comment #5
maki3000 commentedit also would be cool to integrate following ARIA-Features in the webform module:
- aria-reqired for requred fields
- aria-labelledby for errors
There is an attempt to do that here:
https://www.drupal.org/project/webform_aria
Should i make an own ticket for that?
Comment #6
danchadwick commented@mgifford, @maki3000 -- I support someone writing a patch for ARIA support, provided people test it and mark it RTBC.
Comment #7
liam morlandHere is a patch that has the desired effect. However, I really don't like the way that it does it. I don't like how I had to use the "--WEBFORM-PLACEHOLDER--", however, I couldn't find a place where the component had an #id, but had not yet been rendered into #children. Perhaps this happens inside Drupal core. I would appreciate any suggestions for making this better.
If the "--WEBFORM-PLACEHOLDER--" approach is to be used, a regex could allow it to deal with other elements setting @aria-describedby.
Comment #8
liam morland@maki3000, the other ARIA-related things you mention should each get their own tickets.
Comment #9
danchadwick commentedThe maintainers have decided to defer all aria issues to D8. They are marked postponed because they will be looked at after the D8 port is functional.
Comment #10
fenstratClosing to clear out the old Webform 8.x-4.x branch. See #2827845: [roadmap] YAML Form 8.x-1.x to Webform 8.x-5.x.