Hi!

I am building a table and I'm trying to integrate some radio buttons in the table row like this:

          $row[] = array(
            'data' => array(
              '#type' => 'radio',
              '#title_display' => 'invisible',
              '#name' => 'radios_left',
              '#return_value' => $vid,
              '#default_value' => FALSE,
            ),
          );

but I get the following notice:

Undefined index: #value in /var/www/drupal/core/includes/form.inc on line 1147

However I noticed that if I just display the radio button on it's own (not in a table row) the notice dissapears and also the only way of making the notice dissapear when displaying radio button in a table row is to set the '#value' property.

So, I suppose this is a bug, since I should be able to set default value of radio button without being forced to set the value property.

Comments

lhangea’s picture

Title: Radio button in a table notice » Radio button in a table row notice
aron novak’s picture

lhangea’s picture

Status: Active » Needs review
StatusFileSize
new730 bytes

I made a small patch for this.

aron novak’s picture

Issue tags: +Needs tests

afterwards the tests, it's surely RTBC

berdir’s picture

#value is very likely not set because the form fields are not processed by the form system, as they're hidden away below a #rows, so the forms processing doesn't find them.

In Drupal 7, you had to use a complex approach where you built the form without a table and then added a theme function to render it out as a table, after it was processed by the form API.

in Drupal 8, you can use #type => 'table and then instead of #rows, you can basically add your rows just nested below the table render element. Have a look at https://github.com/md-systems/monitoring/blob/introducing-multigraph/mod... and the following lines.

Try that, I think it will then just work and you can close this issue.

lhangea’s picture

Yep, it works as you said. For those interested: https://www.drupal.org/node/1876710

I will close this issue.

Thanks Berdir

lhangea’s picture

Status: Needs review » Closed (works as designed)