V
V
VitaliyKaliuzhyn2017-02-03 18:03:28
Yii
VitaliyKaliuzhyn, 2017-02-03 18:03:28

Customizing checkboxList()?

Good day. There is such a problem.
There is a code

<?=$form->field($model, 'created_at')->checkboxList(['Checkbox 1','Checkbox 2','Checkbox 3'],['class'=>'mt-checkbox-list', 'itemOptions' => ['labelOptions'=>['class'=>'mt-checkbox mt-checkbox-outline']]]); ?>

which generates html markup
<div class="form-group field-users-created_at required">
<label class="control-label" for="users-created_at">Дата создания</label>
<input type="hidden" name="Users[created_at]" value=""><div id="users-created_at" class="mt-checkbox-list"><label class="mt-checkbox"><input type="checkbox" name="Users[created_at][]" value="0"> Checkbox 1</label>
<label class="mt-checkbox"><input type="checkbox" name="Users[created_at][]" value="1"> Checkbox 2</label>
<label class="mt-checkbox"><input type="checkbox" name="Users[created_at][]" value="2"> Checkbox 3</label></div>

<span class="help-block"></span>
</div>

And I need to place inside each label What would happen like this
<div class="form-group field-users-created_at required">
<label class="control-label" for="users-created_at">Дата создания</label>
<input type="hidden" name="Users[created_at]" value=""><div id="users-created_at" class="mt-checkbox-list"><label class="mt-checkbox"><input type="checkbox" name="Users[created_at][]" value="0"> Checkbox 1<span></span></label>
<label class="mt-checkbox"><input type="checkbox" name="Users[created_at][]" value="1"> Checkbox 2<span></span></label>
<label class="mt-checkbox"><input type="checkbox" name="Users[created_at][]" value="2"> Checkbox 3<span></span></label></div>

<span class="help-block"></span>
</div>

That is, I'm interested in how to change the standard template to the one that I need.
Tried this option
$this->template = "<div class='mt-checkbox-list'>{input}<span></span></div>";

but it just adds span after all labels. And I would like to shove this span directly into the label.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2017-02-03
@VitaliyKaliuzhyn

$form->field($model, 'created_at')->checkboxList([
  'Checkbox 1',
  'Checkbox 2',
  'Checkbox 3'
],[
   'item' => function ($index, $label, $name, $checked, $value) {
      return // генерируем чекбокс какой угодно структуры
   }
])

V
VitaliyKaliuzhyn, 2017-02-06
@VitaliyKaliuzhyn

Another question, I asked what I need to return
how do I pass parameters, that is, label itself add a class and input add an attribute.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question