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?
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
This would work definitely:
<?= $form->field($model, 'pid')->dropDownList([1=>1,2=>2], ['options'=>['2'=>['disabled'=>true]]]) ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With