black-room-boy
black-room-boy

Reputation: 659

How to create yii2 inline checkbox list

I have described my problem on yii2 forum, but no one helped me, most likely because no one knows the answer.

Here is the short description here.

I would like to make 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>

but with yii2 checkboxList Html helper.

This is my simplified array of checkbox values

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

I need to insert the class="checkbox-inline" into the label tags of each checkbox generated by this yii2 helper method but I can not figure out how to do it.

I was following these guides: checkboxList and checkbox one ( I can't post more than 2 links because I am new here ) but they are not helpful to me, I just do not understand what I have to do. Everything I tried just failed.

Can someone help me please, I am trying for 3 days now ?

Upvotes: 12

Views: 28508

Answers (1)

soju
soju

Reputation: 25312

You should simply use :

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

http://www.yiiframework.com/doc-2.0/yii-bootstrap-activefield.html#inline()-detail

Upvotes: 23

Related Questions