1

I want to render elements of type checkboxes or radios inside tableselect, but what I get are empty html tags. Textfield and select type elements render fine.

Basically this renders fine.

$tableSelectTesting = array(
  '#type' => 'select',
  '#options' => array(
    "1000" => "$1000",
    "other" => t("Other"),
  ),
);

This does not.

$tableSelectTesting = array(
  '#type' => 'radios',
  '#options' => array(
      "1000" => "$1000",
      "other" => t("Other"),
    ),
);

I add the form element to table select using the 'data' array key.

$options[$index] = array(
    'column1' => $column1Data,
    'column2' => array(
      'data' => $tableSelectTesting,
    )
  );

This is the output I get for the radios element.

<td><div id="some-id" class="form-radios"></div></td>

What should I be doing differently?

bumped to the homepage by Community 2 days ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

I believe you are missing some details in the way you structure your data. Check this example, specifically the data array tree.

Also, check the structure of the array that defines the tableselect. For radios it should look like this:

$form['table'] = array(
  '#type' => 'tableselect',
  '#header' => $header,
  '#options' => $options,
  '#multiple' => FALSE,
);

(the #multiple property is the one that defines whether these are checkboxes or radios)

Your data in the array $options should look something like this:

$options = array(
  '1000' => array(
      'field_price' => '$1000',
  ),
  'other' => array(
      'field_price' => 'Other',
  ),
);

Notice the nested structure, and the field name (this could be anything, but it needs to exist, one for every column of the table, starting with the second column.

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.