2

I am interesting in adding text next to the checkmark in the table #header.

enter image description here

As you can see from the photo there isn't any text there.

My code for the table:

$header = array(
    'campground' => t('Campground'),
    'name' => t('Name'),
    'phone' => t('Phone Number'),
    'message' => t('Message'),
  );

$form['table'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#default_value' => $values,
    '#empty' => t('No campground to claim'),
  );

Is it possible to add a title next to the checkmark?

1

I dont see a direct option to do this. but you could add the required label as header and make it the first column next to the check box. and remove the border to make it look like the are together as a label for the check box.

  • Very Hacky. I decided it not really worth it. It's only an admin panel. Cheers. – John Riselvato Jan 31 '13 at 16:29
3

I ended up needing to keep the label actually in the correct column, and so went a different route. I have jQuery available to me as well.

I added an #after_build to my form that would insert some JavaScript:

$form['#after_build'][] = 'mymodule_config_form_after_build';

Then in that function, added:

function mymodule_config_form_after_build($form, &$form_state) {
$data = <<< EOT
  jQuery(document).ready(function(){
        var liveTable = jQuery("#edit-variables table").filter(function() {return !(jQuery(this).css('visibility') == 'hidden' || jQuery(this).css('display') == 'none');}); // Get the right table
        var cb = jQuery("th.select-all input[type='checkbox']", liveTable); // get the right checkbox
        if (cb.length == 1) { // attempt at being smart
            var th = jQuery("th.select-all", liveTable); // Need the table head next
            th.css('width', '15%'); // I found the auto width logic was messing up the table, so I put in this hack to cover my label width
            cb.attr('name', 'form-select-all');
            cb.attr('id', 'form-select-all');
            var label = jQuery("<label for='form-select-all' style='padding: 0px;'>Active Replacement?</label>");
            cb.before(label).detach().prependTo(label); // put the label in and move the checkbox before it

        }
    });

EOT;
drupal_add_js($data, 'inline');
return $form;

The first jQuery filtering is needed because Drupal seems to add a hidden table to help facilitate header handling (???). I was coming up with too many tables and check boxes.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.