Radio button attribute?

Permalink 1 user found helpful
Hi all

I've recently started a site where using a radio button attribute, instead of a select attribute, would be helpful. I searched the forums but I'm surprised nobody has encountered the same thing.

I thought about repurposing the select attribute for this purpose (the difference is largely aesthetic) but I found the code a bit too sophisticated for my skills.

Has anyone successfully managed to create a radio button attribute? Or any tips on how to achieve it?

View Replies:
rosie607 replied on at Permalink Reply
Did you ever figure this out? I need to do the same thing.
melat0nin replied on at Permalink Reply
I didn't create a new attribute per se, but instead created a custom template for the select attribute form which displays the options as radio buttons instead of as a select widget.

The relevant code is from /concrete/models/attribute/types/select/form.php (copy to /models/attribute/types/select/your_template_name.php) from line 109 to around 125:

$opts = array('' => t('** None'));
      foreach($options as $idx=>$opt) {
                    $opts[$opt->getSelectAttributeOptionID()] = $opt->getSelectAttributeOptionValue();
                    echo $form->radio($this->field('atSelectOptionID') . '[]', $opt->ID, $selected);
                    echo '<label for="'.$this->field('atSelectOptionID') . '[]' . ($idx+1) . '">' . $opt->value . '</label>';
      <?php //echo $form->select($this->field('atSelectOptionID') . '[]', $opts, $selectedOptions[0]); ?>

You can see where I've commented out the select form at the bottom.

That works to display the radio buttons! It's a bit hacky and not as elegant as a proper radio button attribute would be, but it works for me.
ronyDdeveloper replied on at Permalink Reply
Hi Laurence
This is very helpful. I was trying to find a way to create a radio type user attribute. But didn't find any proper solution. Then was started to create a new attribute type. But it was taking too long to write. Then I've found this post.

Anyway do you know, if there is a way to checked a radio by default at the first time?