From 16ad612cbeb83dd8d3edd31b674a7c34151c0185 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Thu, 5 Apr 2012 16:09:10 +0900 Subject: [PATCH] Issue #405360 by Liam Morland, mgifford, Everett Zufelt: Added Use aria-describedby to link form elements with form element descriptions. --- core/includes/form.inc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/includes/form.inc b/core/includes/form.inc index 665a9e655808..335133bb6793 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -1779,6 +1779,12 @@ function form_builder($form_id, &$element, &$form_state) { if (!isset($element['#id'])) { $element['#id'] = drupal_html_id('edit-' . implode('-', $element['#parents'])); } + + // Add the aria-describedby attribute to associate the form control with its + // description. + if (!empty($element['#description'])) { + $element['#attributes']['aria-describedby'] = $element['#id'] . '--description'; + } // Handle input elements. if (!empty($element['#input'])) { _form_builder_handle_input_element($form_id, $element, $form_state); @@ -4186,7 +4192,11 @@ function theme_form_element($variables) { } if (!empty($element['#description'])) { - $output .= '<div class="description">' . $element['#description'] . "</div>\n"; + $attributes = array('class' => 'description'); + if (!empty($element['#id'])) { + $attributes['id'] = $element['#id'] . '--description'; + } + $output .= '<div' . drupal_attributes($attributes) . '>' . $element['#description'] . "</div>\n"; } $output .= "</div>\n"; -- GitLab