Has anyone else run into an accessibility issue when using the form API tableselect element ('#multiple' => FALSE)? The resulting markup is a table with the first column as an input of type radio, but no corresponding label.
Looking at the form_process_tableselect function, I see there is an if block with the following check:
if ($element['#multiple']) {
Within that block it does pull a title out of the options array:
if (!empty($element['#options'][$key]['title']['data']['#title'])) {
$title = t('Update @title', array(
'@title' => $element['#options'][$key]['title']['data']['#title'],
));
}
That only applies if #multiple is TRUE. In the else block it renders the radio column with no title at all:
$element[$key] = array(
'#type' => 'radio',
'#title' => '',
'#return_value' => $key,
'#default_value' => ($element['#default_value'] == $key) ? $key : NULL,
'#attributes' => $element['#attributes'],
'#parents' => $element['#parents'],
'#id' => drupal_html_id('edit-' . implode('-', $parents_for_id)),
'#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
);
Am I missing something? Is Drupal core really missing such a basic accessibility feature? Any recommendations on working around this?
'#type' => 'tableselect'
in snippet you posted. And please simplify it, remove as many variables from your snippet as possible? You know, to minimize guesswork on our part. – Mołot Dec 1 '14 at 22:31