Reputation: 54949
I want to use Radio Button using the Form Helper. A radio button has a Radio element and a Label. I have by default Display: block for Label element. I want to assign a class the the label of the Radio button so that i can assign it a inline-block.
$attributes = array('legend' => false, 'label' => array('class' => 'radioBtn'));
echo $this->Form->radio('gender', $options, $attributes);
How can i assign a class to the label of the option
Upvotes: 2
Views: 12968
Reputation: 11
Work for me:
// Add your own label with CSS class
$opts = array('1' => "<label class='myCSS'>My first option</label>", "2" => "<label class='myCSS'>My second option</label>");
// Put label param to false
echo $this->Form->input('my-input', array('type' => 'radio', 'label' => false, 'options' => $opts, 'legend' => false));
Enjoy
Upvotes: 1
Reputation: 651
How about using FormHelper::label(string $fieldName, string $text, array $options)
You could define the label class in the options array, so (for example):
echo $options = array( /* relevant stuff goes here */ );
echo $attributes = array( /* relevant stuff goes here */ );
echo $this->Form->radio('gender', $options, $attributes);
echo $this->Form->label('gender', 'Text of your label', array('label'=>'radioBtn'))
Source CakePHP Cookbook on FormHelper
Upvotes: 1
Reputation: 5001
By looking at the Form->radio() method code, nothing seems related to attributes belonging to the labels.
But to modify the display of these labels, you could use a surrounding div
echo '<div class="inline_labels">';
echo $this->Form->radio('gender', $options, $attributes);
echo '</div>';
and use CSS like this:
.inline_labels label
{
display: inline-block;
}
Upvotes: 5