I am facing a problem in adding a class to the radio button label in cakephp 3.
My code is :
<?= $this->Form->input('enroll',[
'type'=>'radio',
'options'=>[
[
'value'=>'1',
'text'=>'Yes',
'class'=>'checkbox'
],
[
'value'=>'0',
'text'=>'No',
'class'=>'checkbox'
]
],
'label'=>false
])
?>
This is generating following Html:
<div class="input radio">
<input type="hidden" value="" name="enroll">
<label for="enroll-1">
<input type="radio" id="enroll-1" class="checkbox" value="1" name="enroll">
Yes
</label>
<label for="enroll-0">
<input type="radio" id="enroll-0" class="checkbox" value="0" name="enroll">
No
</label>
</div>
What I Want is:
<div class="input radio">
<input type="hidden" value="" name="enroll">
<label for="enroll-1" class="checked-input">
<input type="radio" id="enroll-1" class="checkbox" value="1" name="enroll">
Yes
</label>
<label for="enroll-0" class="checked-input">
<input type="radio" id="enroll-0" class="checkbox" value="0" name="enroll">
No
</label>
I want a class to be added to the <label for=''>
.
What I Tried was:
<?= $this->Form->input('enroll',[
'type'=>'radio',
'templates'=>[
'label'=>'<label {{attrs}} class="checked-input">{{text}}</label>',
'radioWrapper'=>'{{label}}'
'options'=>[
[
'value'=>'1',
'text'=>'Yes',
'class'=>'checkbox'
],
[
'value'=>'0',
'text'=>'No',
'class'=>'checkbox'
]
],
'label'=>false
])
?>
But I am not able to do that. I have tried lots of other things but they aren't working either. Please help.
simply you have to modify nestingLabel
template instead of label
template
'nestingLabel' => '{{hidden}}<label{{attrs}} class="checked-input">{{input}}{{text}}</label>'
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments