How to create inline checkbox with checkboxList

I want to create this:




<label class="checkbox-inline"><input type="checkbox" value="ASD">Option 1</label>

<label class="checkbox-inline"><input type="checkbox" value="DSA">Option 2</label>

<label class="checkbox-inline"><input type="checkbox" value="REW">Option 3</label>



I can not figure out how to add class="checkbox-inline" to labels. I am reading API docs, but I have no idea what to do, docs are not helpful for me.

Can anyone explain me please ?

DOCS 1, DOCS 2

Now I also see that I can not insert values in database either.

This is my simplified list:




<?= $form->field($model, 'country')->checkboxList(['FR'=>'France', 'DE'=>'Germany']) ?>



I have list of countries that user need to select so I can insert them into database.

I managed to save my records to database thanks to this https://github.com/yiisoft/yii2/issues/2782

But I still do not know how to make my checkboxes inline

I still can not figure out how to create inline checkbox list…

Day 3

It seems that you have to use


function ($index, $label, $name, $checked, $value)

to set the label somehow.

Whatever I tried it doesnt work… I am out of ideas.

By the way its nice talking with myself…

You should simply use :


<?= $form->field($model, 'country')->inline(true()->checkboxList(['FR'=>'France', 'DE'=>'Germany']) ?>

As explained here : http://www.yiiframework.com/doc-2.0/yii-bootstrap-activefield.html

Thanks a lot, I didn’t knew that these options exists.

Do anyone know how I can mark certain checkboxes as checked when form loads? For example I want ‘FR’ to be marked as checked by default.

Thanks