yii2 checkbox value is not required. Only the label is required at the top in yii2 active form.
No options needed on checkbox yii2, Only label at the top is required
384 Views Asked by Amarjeet At
2
There are 2 best solutions below
0
On
There are many ways. You probably want to create a Toggle Switch or ... .
<?= $form->field($model, 'Attribute')->checkbox([
'label' => false, // <label> is the parent of <input>
'style' => 'visibility: hidden !important;', // Or display: none;
])->label('yourLabel', ['style' => 'display:block',]); ?>
Also if the user clicks on the text within the <label> element, it toggles the control.
You can use yii\bootstrap\ActiveForm instead of yii\widgets\ActiveForm for more options.
You can use simple tag() method of HTML helper class in Yii 2. As follows:
Or you can mention only {label} for the template option for that particular field like: