H
H
Herman Martin2018-03-15 19:26:00
Yii
Herman Martin, 2018-03-15 19:26:00

How to customize checkboxList in Yii2?

Good afternoon.
There is a code:

foreach($types as $ck => $cv){
  $naa[$cv['id']] = $cv['name'];
}
echo $form->field($eventMain,'type',[
  'template' => "<label for=''>Выберите тип</label>                                             
  $chechBoxexForTypeFilter
  <div>{input}</div>",
  'options' => ['class' => 'class-radioCheckBox']
])->checkboxList(
  $naa,
  [
                 // 1
    'item' => function($index, $label, $name, $checked, $value) {
      $return = '<label>';
      $return .= '<input type="checkbox" name="' . $name . '"' . 'value="' . $value . '"' . ' >'."\n";
      $return .= '<i class="fa fa-square-o fa-2x"></i>' ."\n" .
      '<i class="fa fa-check-square-o fa-2x"></i>' ."\n";
      $return .= '<span>' . ucwords($label) . '</span>' ."\n";
      $return .= '</label>';

      return $return;
    },
    'id' => 'simpleFilterModal_radioCheckBox'
  ]
);

and the question is, how to forward the array to 'item', in order to put checkboxes on already marked elements by comparing with it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Bay, 2018-03-15
@kawabanga

function($index, $label, $name, $checked, $value)
checked isn't your responsibility for the parameter? check the default template.

M
Mykola, 2018-03-16
@iSensetivity

In order for checked to be passed, $eventMain->type must have an array with checked values.

$eventMain->type = [1, 2, 5];
// а потом уже
...............
echo $form->field($eventMain,'type',[
  'template' => "<label for=''>Выберите тип</label>                                             
  $chechBoxexForTypeFilter
  <div>{input}</div>",
  'options' => ['class' => 'class-radioCheckBox']
])
....................

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question