When I try to use tableselect type in hook_view() function I've got following PHP message:

Notice: Undefined index: #attributes in theme_tableselect() (line 2802 of /var/www/drupal7/includes/form.inc).

// some code: I prepared $header and $options, etc...

 $node->content['something'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('No data available.'),
    '#weigth' => 10
  );

return $node;

Html table has been displayed correctly, but #attributes key should be optional.

Comments

aspilicious’s picture

Version: 7.x-dev » 8.x-dev
Status: Active » Needs review
StatusFileSize
new739 bytes

This should work, didn't test it.

ryan.armstrong’s picture

Got the same error and can confirm that this patch does indeed fix it. Is this something that cannot be put into 7 (Referring to the change from 7.x to 8.x)?

heine’s picture

tableselect is a form element. Are form elements supposed to magically work in other render arrays?

damien tournoud’s picture

Are form elements supposed to magically work in other render arrays?

No, they are not (and most of them don't), but I think we should try.

In that case, the proper fix would probably be to add #attributes as a default for 'tableselect' in system_elements().

john.doe’s picture

Version: 8.x-dev » 7.12

it's seem mistake : and prefore solve method is not work, how can deal with it. give me a idea.
if i follow the step , but it is not work.

heine’s picture

Version: 7.12 » 8.x-dev

To #5, I don't understand what you want.

rob c’s picture

The patch in #1 also works for D7.14.

Status: Needs review » Needs work

The last submitted patch, 1: 877674-attributs-optional.patch, failed testing.

alansaviolobo’s picture

Issue summary: View changes
Issue tags: +Needs reroll
lokapujya’s picture

In D8, the table doesn't render from a render array (and the notice is not created.) The table only renders in a form.

jyotisankar’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Needs work » Needs review
Issue tags: +#SprintWeekend2015
StatusFileSize
new579 bytes
David Hernández’s picture

Issue tags: -#SprintWeekend2015 +SprintWeekend2015

Hello!

Thank you for working on this issue!

We should all try and use the same sprint tag. According to https://groups.drupal.org/node/447258 it should be SprintWeekend2015 with no #.

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.