Monday, May 30, 2011

check all / uncheck all checkbox drupal

<?php
function myModule_batch_add_opp_form($form_state) {
  $form = array();

  $nid_contactCheckUncheckAll_js = <<< EOD
    Drupal.behaviors.nid_contactCheckUncheckAll = function(context) {
      $('#edit-nid-contact-').click(function(event) {
        $('#myModule-batch-add-opp-form').find('input[@type=checkbox]').each(function() {
          this.checked = $('#edit-nid-contact-').attr('checked');
        });
      });
    };
EOD;

  drupal_add_js($nid_contactCheckUncheckAll_js, 'inline');

  $form['nid_contact'] = array(
    '#type' => 'checkboxes',
    '#title' => 'Select Contacts',
    '#options' => array('' => 'Check / Uncheck All') + myModule_nid_contactArr(),
    '#required' => TRUE,
  );

  return $form;
}
?>

No comments: