labels related to checkboxed should be associated to them. i just came across this when clicking on the "Select all items on this page" label didn't mark the checkbox as selected.

if possible we would need a unique id for the checkbox and set the "for" attribute of the label accordingly.
another option is to put the checkbox inside the label element.
http://www.456bereastreet.com/archive/200711/use_the_label_element_to_ma...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz’s picture

Category: feature » bug

I'm not actually doing anything special here:

    $form['select_all'] = array(
      '#type' => 'fieldset',
      '#attributes' => array('class' => array('vbo-fieldset-select-all')),
    );
    $form['select_all']['this_page'] = array(
      '#type' => 'checkbox',
      '#title' => t('Select all items on this page'),
      '#default_value' => '',
      '#attributes' => array('class' => array('vbo-select-this-page')),
    );

    if ($enable_select_all_pages) {
      $form['select_all']['or'] = array(
        '#type' => 'markup',
        '#markup' => '<em>OR</em>',
      );
      $form['select_all']['all_pages'] = array(
        '#type' => 'checkbox',
        '#title' => t('Select all items on all pages'),
        '#default_value' => '',
        '#attributes' => array('class' => array('vbo-select-all-pages')),
      );
    }
  }

So the question is: why does it fail...

liquidcms’s picture

i think somewhat related. i have a grid layout and i get a select all on this page checkbox and a select all on all pages checkbox with an OR between them.

to start with, the view is not set to use paging; so silly to have both checkboxes as they are now technically the same thing; but regardless of that, if there was some wort of id or class assigned to a wrapper around the checkboxes, labels and even the OR, it would be possible in css to hide these.

i looked at a form_alter but not available at that time to alter; looking next at after_submit function; failing that i guess only solution is use JS or to write a patch to add some way that css can simply hide these.

texas-bronius’s picture

FileSize
102.87 KB

It's a good question, if the above code is producing the Select All (Pages) checkboxes. However, the derivative markup that is on the VBO form I am dealing with appears to a) be from a FAPI #markup element and b) not show when Javascript is disabled. Here's the dpm/kpr out of $form in a hook_views_bulk_operations_form_alter:
Screenshot of $form kpr
Something else is going on.

texas-bronius’s picture

Title: "Select all items on this page" label should have for attribute » Click on "Select all items on this page" checkbox label does not affect checkbox: missing "for" html attribute

But in the meantime, from the desk drawers labeled "Don't work around it like this," you can work around like this:

/**
 * Implements hook_views_bulk_operations_form_alter().
 * @param type $form
 * @param type $form_state
 * @param type $vbo
 */
function vbo_single_serve_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) {
  if ($form_state['step'] == 'views_form_views_form') {
    // Alter the first step of the VBO form (the selection page).
    ...
    $selectallmarkup = $form['select_all_markup']['#markup'];
    $selectallmarkup = str_replace('<input class="vbo-select-this-page form-checkbox"', '<input class="vbo-select-this-page form-checkbox" id="vbo-select-this-page"', $selectallmarkup);
    $selectallmarkup = str_replace('<input class="vbo-select-all form-checkbox"', '<input class="vbo-select-all form-checkbox" id="vbo-select-all"', $selectallmarkup);
    $selectallmarkup = preg_replace('/<label class="option">/', '<label class="option" for="vbo-select-this-page">', $selectallmarkup, 1);
    $selectallmarkup = preg_replace('/<label class="option">/', '<label class="option" for="vbo-select-all">', $selectallmarkup, 1);
    $form['select_all_markup']['#markup'] = $selectallmarkup;

Rough and tumble, toil and bumble..

madhaze’s picture

It seems like all form items should have an id and checkboxes should have a with the for="xxx" (xxx being the inputs id) Due to VBO not using this standard format i'm having issues styling forms to look consistent. I might look to do what is mentioned above as a work around. That or find a js option possibly

j1mb0b’s picture

Issue summary: View changes

Actually, the form is not being built correctly it should calling drupal_get_form before drupal_render since it's within that function the call is made eventually to:

https://api.drupal.org/api/drupal/includes%21form.inc/function/form_buil... - which is responsible for settings the #id property on the element.

Therefore, the form build could be set outside the theme function as a standalone form function, which allows you to call drupal_render.

crutch’s picture

FileSize
9.02 KB

There is no way that I can find to make a label effect the checkbox for a views-row.

Alex Bukach’s picture

Status: Active » Needs review
FileSize
677 bytes

Why cannot it be as easy as this one?

Alex Bukach’s picture

Corrected paths in the patch.

dmundra’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
637 bytes

@alex-bukach I believe you addition does work but no label is automatically added to the checkbox. I am actually solving a different problem which is that the lack of the label is an accessibility issue. So I think we should combine your solution with

dmundra’s picture

Status: Reviewed & tested by the community » Needs review

I created a related issue https://www.drupal.org/project/views_bulk_operations/issues/3388986 that tackles the missing labels. Maybe that should include the unique ID solution from here?