any way to add class to radio labels

mikeb
Member | 32
+
0
-

Hi
i'm using forms only, not latte. when i addRadioList how can I add a class to the label of the radio (not the input or to control pair label). eg:

$form->addRadioList('gender', 'Gender:', $sex) //...

renders

<label class="ADD-MY-CLASS-HERE"><input type="radio" name="gender" value="m" data-lfv-initialized="true" data-lfv-message-id="frm-eval-gender_message">male</label>

I can't even think how to access it in a custom rendered.

Thanks for any suggestions.

nightfish
Member | 516
+
+2
-

@mikeb
Let's assume

$sex = ['m' => 'male', 'f' => 'female'];
$radioList = $form->addRadioList('gender', 'Gender:', $sex);

If you want to apply specific class for Gender: <label>, use

$radiolist->getLabelPrototype()->appendAttribute('class', 'your-custom-class');

If you want to apply classes to <label>s of male and female radio list items, use

$radioList->getLabelItemPrototype()->appendAttribute('class', 'your-custom-class');

(both labels male and female will get the same class).

If you want to apply different classes to labels of male and female, use

$radioList->getLabelItemPrototype()->appendAttribute('class:', ['m' => 'male-class', 'f' => 'female-class']);

(note the colon after class – that means that attribute value is set based on respective item's value).

If you would want to apply classes to <input> in radio list, use $radioList->getControlPrototype()->appendAttribute() instead.