Yii2: How to add an event onchange in checklist on yii2

Created on 22 Apr 2016  路  2Comments  路  Source: yiisoft/yii2

I have my checklist, but I want to call an a function js, as if an activeCheckbox.

$form->field($model, 'attributes')->label('')->checkboxList(Model::getAttributes(),
                                ('onclick' => 'functionJS()'),
                                [
                                    'item'=>function ($index, $label, $name, $checked, $value){
                                    return '<div class="col-md-2" style="text-align:left">' . Html::checkbox($name,  $checked, [
                                            'class' => 'flat',
                                            'value' => $value,
                                            'label' => html::encode($label),
                                            'id' => $index
                                            ]) . '</div>';
                                        }
                                ]
                           );

Additional info

| Yii version 2 |
| PHP version 5.6 |
| Operating system Linux|

question

Most helpful comment

_This is an automated comment, triggered by adding the label question._

Please note, that the GitHub Issue Tracker is for bug reports and feature requests only.

We are happy to help you on the support forum, on IRC (#yii on freenode), or Gitter.

Please use one of the above mentioned resources to discuss the problem.
If the result of the discussion turns out that there really is a bug in the framework, feel free to
come back and provide information on how to reproduce the issue. This issue will be closed for now.

All 2 comments

_This is an automated comment, triggered by adding the label question._

Please note, that the GitHub Issue Tracker is for bug reports and feature requests only.

We are happy to help you on the support forum, on IRC (#yii on freenode), or Gitter.

Please use one of the above mentioned resources to discuss the problem.
If the result of the discussion turns out that there really is a bug in the framework, feel free to
come back and provide information on how to reproduce the issue. This issue will be closed for now.

We can add checklist field in simple way using yii.
In view file,
$form->labelEx($user, 'joblist');
class="crse_container" (Note - Add class in div)
$form->checkBoxList($user, 'joblist',$cat_types);
$form->error($user, 'joblist');

then add the styles in css file like
.crse_container { border:1px solid #ccc; height: 200px;width: 250px; overflow-y: scroll;}
joblist

Was this page helpful?
0 / 5 - 0 ratings