Add attribute to yii2 checkboxlist container div

I’m trying to use custom template for yii2 checkboxlist I’m using the code:


<?=

 $form->field($model, 'fruit_ids')->checkboxList($fruits, [

        'item' => function($index, $label, $name, $checked, $value) {

            return "<label class='col-md-4'><input type='checkbox' {$checked} name='{$name}' value='{$value}'>{$label}</label>";

        }

]);

?>

Which output:


<div id="testform-fruit_ids">

    <label class="col-md-4"><input type="checkbox" name="TestForm[fruit_ids][]" value="0">Apple</label>

    <label class="col-md-4"><input type="checkbox" name="TestForm[fruit_ids][]" value="1">Banana</label>

    <label class="col-md-4"><input type="checkbox" name="TestForm[fruit_ids][]" value="2">Orange</label>

    <label class="col-md-4"><input type="checkbox" name="TestForm[fruit_ids][]" value="3">Pear</label>

    <label class="col-md-4"><input type="checkbox" name="TestForm[fruit_ids][]" value="4">Pineapple</label>

</div>

But I want to add attribute [b]


class="btn-checkbox options"

[/b] and [b]


data-toggle="button"

[/b] to [b]


<div id="testform-fruit_ids">

[/b] wrapper div element, i.e. I want the output like:


<div id="testform-fruit_ids" class="btn-checkbox options" data-toggle="button">

    <label class="col-md-4"><input type="checkbox" name="TestForm[fruit_ids][]" value="0">Apple</label>

    <label class="col-md-4"><input type="checkbox" name="TestForm[fruit_ids][]" value="1">Banana</label>

    <label class="col-md-4"><input type="checkbox" name="TestForm[fruit_ids][]" value="2">Orange</label>

    <label class="col-md-4"><input type="checkbox" name="TestForm[fruit_ids][]" value="3">Pear</label>

    <label class="col-md-4"><input type="checkbox" name="TestForm[fruit_ids][]" value="4">Pineapple</label>

</div>

Please tell me the correct way to do it.

Try




<?=

 $form->field($model, 'fruit_ids')->checkboxList($fruits, [

        'class' => "btn-checkbox options",

        'data-toggle' => "button",

        'item' => function($index, $label, $name, $checked, $value) {

            return "<label class='col-md-4'><input type='checkbox' {$checked} name='{$name}' value='{$value}'>{$label}</label>";

        }

]);

?>