如何禁用 yii2 ActiveFrom dropDownList 中的一项? [英] how to disable one item in yii2 ActiveFrom dropDownList?
本文介绍了如何禁用 yii2 ActiveFrom dropDownList 中的一项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Yii2 主动表单
<?= $form->field($model, 'pid')->dropDownList([1=>1,2=>2])->hint('上级分类') ?>
我想禁用选项 2=>2.
I want to disable the option item 2=>2.
有办法吗?
推荐答案
您可以使用选项"键为下拉列表中的所有项目添加属性.假设您要禁用第二项.
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('上级分类') ?>
在文档中:http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#activeDropDownList()-detail
这篇关于如何禁用 yii2 ActiveFrom dropDownList 中的一项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文