- Status changed to Needs work
almost 2 years ago 4:15pm 21 January 2023
If a form element ID is explicitly assigned with the #id
property, the associated label's for
property will correctly reference that id.
If a form element ID is explicitly assigned via the 'id' property in #attributes
, the id
is correctly assigned, but the label's for
attribute references does not reference that id, instead using what the ID would have been had the ID been automatically generated.
1. Add the search block to the page
2. Add a preprocess form alter hook to the .theme file, and set the form ID
function SUBTHEME_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// This is for Drupal core search block.
if ($form_id == 'search_block_form') {
$form['keys']['#attributes']['id'][] = 'cd-search';
}
}
3. Clear cache and reload page. Notice the form label's ID does not reference the form ID but instead defaults to for="edit-keys"
Have id and for match for accessibility reasons.
Before
After
None
None
None
Fixes form inputs where the element ID is explicitly assigned with the #id property, the associated label's for property will correctly reference that id.
Needs work
10.1 β¨
Last updated
It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.