Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disable one item in yii2 ActiveFrom dropDownList?

Tags:

yii2

Yii2 active form

<?= $form->field($model, 'pid')->dropDownList([1=>1,2=>2])->hint('上级分类') ?>

I want to disable the option item 2=>2.

Is there a way to do it?

like image 365
Xiu Hong Avatar asked Jan 08 '23 21:01

Xiu Hong


2 Answers

You can add attributes for all items in the dropdownlist with the 'options' key. Let's say you want to disable the second item.

<?= $form->field($model, 'pid')->dropDownList([1 => 1, 2 => 2], ['options' => [2 => ['disabled' => true]]])->hint('上级分类') ?>

In the docs: http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#activeDropDownList()-detail

like image 137
Jap Mul Avatar answered Jan 24 '23 12:01

Jap Mul


This would work definitely:

<?= $form->field($model, 'pid')->dropDownList([1=>1,2=>2], ['options'=>['2'=>['disabled'=>true]]]) ?>
like image 31
Ankush Rishi Avatar answered Jan 24 '23 11:01

Ankush Rishi