将 class 添加到 cakephp 3 中单选按钮的标签
Add class to the label for radio button in cakephp 3
我在向 cakephp 3 中的单选按钮标签添加 class 时遇到问题。
我的代码是:
<?= $this->Form->input('enroll',[
'type'=>'radio',
'options'=>[
[
'value'=>'1',
'text'=>'Yes',
'class'=>'checkbox'
],
[
'value'=>'0',
'text'=>'No',
'class'=>'checkbox'
]
],
'label'=>false
])
?>
这是生成以下 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>
我想要的是:
<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>
我想要 class 添加到 <label for=''>
。
我试过的是:
<?= $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
])
?>
但我做不到。我已经尝试了很多其他的东西,但它们也没有用。请帮忙。
只需修改 nestingLabel
模板而不是 label
模板
'nestingLabel' => '{{hidden}}<label{{attrs}} class="checked-input">{{input}}{{text}}</label>'
这也有效。
<?= $this->Form->input('current_password', [
'type' => 'password',
'required' => true,
'label' => ['class' => 'hello']]);
?>
我在向 cakephp 3 中的单选按钮标签添加 class 时遇到问题。
我的代码是:
<?= $this->Form->input('enroll',[
'type'=>'radio',
'options'=>[
[
'value'=>'1',
'text'=>'Yes',
'class'=>'checkbox'
],
[
'value'=>'0',
'text'=>'No',
'class'=>'checkbox'
]
],
'label'=>false
])
?>
这是生成以下 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>
我想要的是:
<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>
我想要 class 添加到 <label for=''>
。
我试过的是:
<?= $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
])
?>
但我做不到。我已经尝试了很多其他的东西,但它们也没有用。请帮忙。
只需修改 nestingLabel
模板而不是 label
模板
'nestingLabel' => '{{hidden}}<label{{attrs}} class="checked-input">{{input}}{{text}}</label>'
这也有效。
<?= $this->Form->input('current_password', [
'type' => 'password',
'required' => true,
'label' => ['class' => 'hello']]);
?>