ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### 方法 动态下拉选择控件实例: ```php $select2= $formControl->selectDynamic(); ``` select2配置项: 1. 选择后,不关闭选项内容 ```php $select2->unCloseOnSelect(); ``` 2. 其他配置项设置 ~~~ $select2->uiConfig($key, $value); // 示例 1 $select2->uiConfig('allowClear', false); // 是否允许清除选中 // 示例 2 $select2->uiConfig('width', '120px'); // 控件宽 // 示例 3 $select2->uiConfig('selectedInOrder', false); // 多选时,是否按选择顺序排序 // 示例 4 $select2->uiConfig('selectedHideOption', false); // 多选时,是否隐藏已选择过的选项 ~~~ 设置刷新按钮: ```php $select2->refreshBtn() ``` 设置新增按钮位置:`left|right` ```php $select2->additionBtnPosition('left'); ``` 设置刷新按钮位置:`left|right` ```php $select2->refreshBtnPosition('right'); ``` 设置动态数据选项: ```php $select2->dataUrl('admin/link') ``` > 动态数据选项格式 ```php public function actionLink() { $res = [ '中国' => [ ['value' => 'D', 'text' => '郑州市', 'disabled' => true], ['value' => 'E', 'text' => '东莞市'], ['value' => 'F', 'text' => '北京市'], ], '美国' => [ ['value' => 'G', 'text' => '西安市', 'disabled' => true], ['value' => 'H', 'text' => '新乡市'], ['value' => 'I', 'text' => '洛阳市'], ], ]; $res2 = [ ['value' => 'D', 'text' => '郑州市', 'disabled' => false], ['value' => 'E', 'text' => '东莞市'], ['value' => 'F', 'text' => '北京市'], ['value' => 'G', 'text' => '新乡市'], ['value' => 'H', 'text' => '洛阳市'], ['value' => 'I', 'text' => '开封市'], ['value' => 'IE', 'text' => '开封市2222'], ]; return $this->asOk('success', $res2); } ``` 动态新增 1. 依赖注入 ```php $select->additionBtn(function(DselectModal $model) { return $modal->route('form/addition')->title('新增')->height(230); }) ``` 2. DsType ```php $dselectModel = new DselectModal; $select->additionBtn($dselectModel->route('form/addition')->title('新增')->height(230)) ``` 3. array数组 ```php // modal模态框 $select->additionBtn([ 'type' => 'modal', 'route' => Url::to('admin/get-all', ''), 'width' => '620px', // 指定modal的宽; 'height' => '750px',// 指定modal的高; 'title' => '',//指定modal标题 'closeBtn' => 0,//是否显示底部关闭按钮 ]) // page单页 $select->additionBtn([ 'type' => 'page', 'route' => Url::to('admin/get-all', ''), 'target' => '_blank', //支持有效的JS窗口对象 'window' => 'top', ]) ``` 设置多选分组选项: ```php $select2->options([ // 分组名称 '会员列表' => [ 'A' => '数字1', // 选择项 'B' => '数字2', 'C' => '数字3', ], '日志列表' => [ 'D' => '日志1', 'E' => '日志2', 'F' => '日志3', ], ]); ``` 设置禁用项: ```php $select->disabled([ 'A', 'D', ]); ``` 设置多选: ```php $select->multiple(); ``` 设置控件标签: ```php $select2->label('下拉选择'); ``` 设置占位提示: ```php $select2->placeholder('请选择'); ``` 设置默认值: ```php $select2->defaultValue('B'); ``` 设置为必填: ```php $select2->required(true); ``` 设置注释文本: ```php $select2->comment('这里是一个注释文本'); ``` 设置栅栏布局 (默认:12`): ```php $select2->layout(6); ``` 设置ui类: ```php $select2->uiClass(['f13']); ``` 设置style样式: ```php $select2->style(); ``` 设置html属性: ```php $select2->attribute(); ``` ### 链式调用 ~~~ $formBuilder->setFormControl([ 'a' => $this->formControl->text()->label('普通文本'), 'b' => $this->formControl->selectDynamic() ->label('动态下拉1') ->layout(12) ->required() ->placeholder('请填写一下') ->defaultValue(['F']) ->unCloseOnSelect() ->multiple() //->refreshBtn() //->refreshBtnPosition() ->additionBtn(function (DselectModal $modal) { return $modal->route('form/addition')->title('新增')->height(230); }) //->additionBtnPosition() ->dataUrl('form/link') ->comment(''), ]); ~~~ ### 代码示例 ~~~ /** * @return string * @throws \ReflectionException * @throws \builder\base\UndefinedParamsException * @throws \yii\base\InvalidConfigException */ public function actionDynamicSelect() { if ($this->isPost) { return $this->asOk('提交成功'); } else { $formBuilder = FormBuilder::instance(); $formBuilder->setTitle('动态下拉框') ->setRequiredStyle() ->setFormControl([ 'a' => $this->formControl->text()->label('普通文本'), 'b' => $this->formControl->selectDynamic() ->label('动态下拉1') ->layout(12) ->required() ->placeholder('请填写一下') ->defaultValue(['F']) ->unCloseOnSelect() ->multiple() //->refreshBtn() //->refreshBtnPosition() ->additionBtn(function (DselectModal $modal) { return $modal->route('form/addition')->title('新增')->height(230); }) //->additionBtnPosition() ->dataUrl('form/link') ->comment(''), ]) ->setResetBtn() ->setSubmitBtn(); return $formBuilder->render(); } } ~~~