i would like to know is there any standard way to do "Select all Checkboxes" in drupal module development?

i m developing a module that will list multiple items with a checkbox to each one. i would like to add a Select All link, a button, or a checkbox to click to select all the checkboxes. then i can delete all the selected items or move to other area.....

is there any standard way to do so?

thanks a lot.

Comments

ThomasH’s picture

There's a simple way to do so with the Jquery lib that is standard with drupal... Or you want the PHP processing too?

sisyphus’s picture

i found out this discussion:
http://drupal.org/node/249669

but i still do not know how to implement using tableselect.js. any instruction.

i would like to know how to do this using PHP programming. any idea?

thanks a lot.

sisyphus’s picture

i saw there are some javascript to implement "select all":
http://www.somacon.com/p117.php

is it possible to embed the code into drupal module?

thanks

sisyphus’s picture

anyone help me on this please.

johnhanley’s picture

There are examples of this exact behavior in the core. For instance the admin user list (admin/user/user). Examine the associated code in user.module and you will find it's quite straightforward to implement. I have done so many times.

-------------------------------------------------------

"The sting in any rebuke is the truth." - Benjamin Franklin

sisyphus’s picture

thank you.

would u pls direct me to the approx no of the line of user.module implementing this feature?

thanks a lot.

johnhanley’s picture

As mentioned in my previous message you need to examine the code in the function associated with the menu path admin/user/user, which can be found in user.admin.inc (for Drupal 6.x.) The code may or may not make sense depending on your familiarity with PHP and the Drupal API. You might be better off going with the contributed module mentioned in this thread.

-------------------------------------------------------

"The sting in any rebuke is the truth." - Benjamin Franklin

markus_petrux’s picture

Doubt is the beginning, not the end of wisdom.

peem83’s picture

I think the simplest way to do this is add "theme('table_select_header_cell')" in first element of header. That how it works in user module and I'm using that in my own modules.

johnhanley’s picture

You don't need a module to add check all functionality.

markus_petrux’s picture

The tableSelect behavior in Drupal 6 only supports check all for a single set of checkboxes. But, it doesn't work if you want more than one, nor for regular checkboxes elements (without a table).

Doubt is the beginning, not the end of wisdom.

robby.smith’s picture

can anyone that was able to figure this out post their code?
i am trying to achieve text (for example "odd", "even", "all") on the node form that a user can click to select checkboxes in the field (field has 50-100 checkboxes)

thanks!

johnhanley’s picture

Search the core files (via your favorite IDE) for the string "theme('table_select_header_cell')" and you will find several examples of how to implement check all functionality in a custom module form.

robby.smith’s picture

Thanks! I will look for the examples. I am also looking to target just one checkbox or a specific selection of checkboxes instead of all checkboxes. Can this also be done? Could someone point me in the right direction or provide a sample code? Thanks so much!

tutumlum’s picture

Simple way to add check all check box by using form api

  drupal_add_js("
    function checkUncheckAll(theElement){
      var theForm = theElement.form, z = 0;
      for(z=0; z<theForm.length;z++){
        if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
          theForm[z].checked = theElement.checked;
        }
      }
    }
  ", 'inline');
  $form['checkall'] = array(
    '#type' => 'checkbox',
    '#title' => t('Select / Unselect all'),
    '#attributes' => array('onclick' => 'checkUncheckAll(this);'),
    '#weight' => -1,
  );
scotthorn’s picture

This worked like a charm (I'm on drupal 7, not sure if that makes a difference in this instance).

Thanks!

Countzero’s picture

Not very subtle, but deadly efficient for a temporary task.

kamranzafar’s picture

Thanks "John Hanley" theme('table_select_header_cell') works.

jaypan’s picture


Contact me to contract me for D7 -> D10/11 migrations.
Or anything really. I'm friendly, and open to work or conversation.