any way to add class to radio labels
- mikeb
- Member | 33
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 | 517
@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.
- mikeb
- Member | 33
Thanks very much nightfish – I'll try that.
EDIT: getLabelItemPrototype() returns an undefined method. I'm using 3.1.8 but can't see it or find it in newer releases or the docs. Am i missing something
EDIT2: ok found it: getItemLabelPrototype()
Thanks
Last edited by mikeb (2024-11-07 08:55)