1

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?

  • Is this happening when you switch to one of the core themes? And how does your code look like? I mean, there is no '#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
  • @Mołot That code I posted is from Drupal core: includes\form.inc function form_process_tableselect($element). It doesn't really matter what my code looks like when they are setting a blank title: '#title' => ''. My code looks just like the sample provided on the form API reference with the title array set: 'title' => array( 'data' => array('#title' => "{$member->full_name}'")) – Stephen Dec 1 '14 at 22:37
  • If you are trying to report a core bug, you are on wrong page, you should be posting in issue queue on drupal.org if it does not about code you wrote. Bugreports are not allowed here, see Help Center. – Mołot Dec 1 '14 at 22:39
  • This seems a perfectly legitimate question, especially for the workaround part. Drupal has hooks that allows to alter its behavior; an answer pointing out which hook and which code to use in that hook would be perfectly fine. – kiamlaluno Dec 2 '14 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.