ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### 方法 下拉选择控件实例: ```php $select2= $formControl->select(); ``` 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->options([ 'yes' => '是', 'no' => '否', ]); ``` 设置多选分组选项: ```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(); ``` ### 链式调用 ~~~ $this->formControl->select()->label('分组')->multiple()->disabled(['A', 'E'])->options([ '会员列表' => [ 'A' => '数字1', 'B' => '数字2', 'C' => '数字3', ], '日志列表' => [ 'D' => '日志1', 'E' => '日志2', 'F' => '日志3', ], ]), ~~~ ### 代码示例 ~~~ /** * @return string * @throws \Throwable */ public function actionIndex() { if ($this->isPost) { return $this->asOk('success', [ 'a' => '1555' ]); } else { $form = FormBuilder::instance([ 'id' => 'formDemo', ]); $form->setTitle('表单构建器') ->setRootLayout([ 'class' => ['col-md-12'] ]) ->setPartial(false) ->setRequiredStyle() ->registerPointcut(H5::alert('我是一个信息提示!')) ->setFormControl([ 'b' => $this->formControl->password()->label('密码')->placeholder('请填写密码')->comment('注:密码必须包含特殊字符,且大于6位小于22位'), 'i' => $this->formControl->select()->label('触发器')->options(['a' => '触发A', 'b' => '触发B']), 'aa' => $this->formControl->xselect()->label('xselect')->data([ ['name' => 'n1', 'value' => 1], ['name' => 'n2', 'value' => 2], ['name' => 'n3', 'value' => 3], ['name' => 'n4', 'value' => 4], ['name' => 'n5', 'value' => 5], ])->radio()->clickClose(), 'n' => $this->formControl->sw()->label('开关')->checked(), 'trigger1' => $this->formControl->trigger()->when('default', 'i', '!=', 'b')->andWhen('default', 'aa', '==', 3)->triggerItems([ 'j' => $this->formControl->text()->label('触发器1-1'), 'k' => $this->formControl->text()->label('触发器1-2'), 'trigger3' => $this->formControl->trigger()->when('default', 'n', '==', '0')->triggerItems([ 'o' => $this->formControl->text()->label('内部触发器1-1'), 'p' => $this->formControl->text()->label('内部触发器1-2'), ])->display(), ])->display(), 'trigger2' => $this->formControl->trigger()->when('default', 'i', '==', 'b')->triggerItems([ 'l' => $this->formControl->text()->label('触发器2-1'), 'm' => $this->formControl->text()->label('触发器2-2'), ])->display(), 'e' => $this->formControl->select()->label('分组')->multiple()->disabled(['A', 'E'])->options([ '会员列表' => [ 'A' => '数字1', 'B' => '数字2', 'C' => '数字3', ], '日志列表' => [ 'D' => '日志1', 'E' => '日志2', 'F' => '日志3', ], ]), 'f' => $this->formControl->selectLink()->label('省')->disabled(['A', 'E'])->initOptions([ '中国' => [ 'A' => '河南省', 'B' => '广东省', 'C' => '北京市', ], '美国' => [ 'D' => '华盛顿', 'E' => '剑桥', 'F' => '麻省理工', ], ])->targetLink('g')->route('form/link')->start(), 'g' => $this->formControl->selectLink()->label('市')->targetLink('h')->route('form/link')->through(), 'h' => $this->formControl->selectLink()->label('县(区)')->end(), ]) ->setSubmitConfirm() ->setExtraBtn([ H5::tag('button', '额外的按钮', ['class' => ['layui-btn layui-btn-sm layui-btn-gray ym2-form-extra-ui'], 'type' => 'button']), ]) ->setSubmitBtn('确定') ->setResetBtn() ->setExtraJs([ function () { return "console.log('额外的JS')"; }, ]) ->setSubmittedRedirect(function (Modal $modal) { return $modal->route('form/vlink')->title('我是狗')->params(['bbbb' => 1, 'c' => ':a'])->closeBtn()->width(800)->height(800); }) ->registerPointcut(H5::alert('我是一个底部信息提示!', 'info'), FormBuilder::POS_END); return $form->render(); } } ~~~