G
G
gomer17262018-04-11 18:40:07
Yii
gomer1726, 2018-04-11 18:40:07

How to make checkbox checked in Yii2?

Hello

<?=$edit_form->field($model, 'serv1')->checkbox([ 'value' => '1'])->label('');?>

How to make it checked ? as we suppose
<input type="checkbox" name="serv1" value="1" checked>

Tried to use checked properties etc.
But it doesn't work.
It only exits checked if value is false

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
gomer1726, 2018-04-20
@gomer1726

The guys figured out the need for the 'checked ' attribute with an extra space
<?=$edit_form->field($model, 'serv1')->checkbox([ 'value' => '1', 'checked ' => true])-> label('');?>

I
Igor Vasiliev, 2018-04-11
@Isolution666

If the checkbox is NOT needed by default:

...
<?php
$page->text = 'я принимаю пользовательское соглашение';
?>
...
<?=$form->field($model, 'serv1')->checkbox(['uncheck' => $page->text, 'value' => $page->text, 'label' => '$page->text]); ?>

if the flag is REQUIRED :
--
Or, as Maxim Fedorov said , we take it and declare it in an action in the controller.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question