how to disable one item in yii2 ActiveFrom CheckBoxList?

hi guys,

how can I prevent selecting an item of a CheckBoxList, which is default?

I try like this, but I don’t succeed. I won’t get any error, but it’s also ineffective





    <div class="col-md-12">

        <?=

        $form->field($ZMailAusgangEmpfaenger, 'id_empfaenger_art')->checkboxList([0 => 'an', 1 => 'bc', 2 => 'bcc'], ['options' => ['0' => ['disabled' => true]]]);

        ?>

    </div>



My intention is that User must see this default element, but he shouldn’t be able to change it. Only changing element two and three should be possible


echo \yii\helpers\Html::checkboxList('asd', [], ['asd', 'dsa'], [

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

        return \yii\helpers\Html::checkbox($name, $checked, [

            'value' => $value,

            'disabled' => $value == '0',

            'label' => $label

        ]);

    },

]);

I’m not in GridView, so I don’t use anyonymous function. I’m in formular using ActiveForm

Yes, you can use anonymous function like this in an ActiveForm!!

You can use Html::checkboxList in an ActiveForm.

Or, you may use Html::activeCheckboxList which also supports anonymous function.

Check the API reference.

http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#activeCheckboxList()-detail

Oh, I didn’t know this circumstance. Now, after having studied ur link, I know it better.

Thx for this.

This thread can be closed as successfully solved