13

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 ?

1 Answer 1

24

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks a lot, I didn't know that those options exists at all.
Do you maybe know how to mark some fields as checked by default ? Let's say that I want to mark FR (France) as checked when form loads.
@black-room-boy As for checking something by default (when form loads), it depends on how you render your checkBoxList? Whether you do this by a simple HTML helper classes or as an ActiveField, being part of ActiveForm. This question and following answer should help you, as it discusses both approaches to this problem.
How can we save them it database and show them checked in view

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.