ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### 方法 下拉联动控件实例: ```php $selectLink= $formControl->selectLink(); ``` select2配置项: 1. 选择后,不关闭选项内容 ```php $selectLink->unCloseOnSelect(); ``` 2. 其他配置项设置 ~~~ $selectLink->uiConfig($key, $value); // 示例 1 $selectLink->uiConfig('allowClear', false); // 是否允许清除选中 // 示例 2 $selectLink->uiConfig('width', '120px'); // 控件宽 // 示例 3 $selectLink->uiConfig('selectedInOrder', false); // 多选时,是否按选择顺序排序 // 示例 4 $selectLink->uiConfig('selectedHideOption', false); // 多选时,是否隐藏已选择过的选项 ~~~ 设置选项: ```php $selectLink->initOptions([ 'yes' => '是', 'no' => '否', ]); ``` 设置分组选项: ```php $selectLink->initOptions([ // 分组名称 '会员列表' => [ 'A' => '数字1', // 选择项 'B' => '数字2', 'C' => '数字3', ], '日志列表' => [ 'D' => '日志1', 'E' => '日志2', 'F' => '日志3', ], ]); ``` 设置目标连接: | 参数 | 默认值 | 名称 | | --- | --- | --- | | field | - | 字段 | | groupField | default | 表单分组 | ```php $selectLink->targetLink($field, $groupField); ``` 设置AJAX路由: > 返回值: ```php // 响应示例1: return $this->asOk('success', [ ['value' => 'D', 'text' => '郑州市', 'disabled' => true], ['value' => 'E', 'text' => '东莞市'], ['value' => 'F', 'text' => '北京市'], ]); // 响应示例2: return $this->asOk('success', [ '中国' => [ ['value' => 'D', 'text' => '郑州市', 'disabled' => true], ['value' => 'E', 'text' => '东莞市'], ['value' => 'F', 'text' => '北京市'], ], '美国' => [ ['value' => 'E', 'text' => '东莞市'], ['value' => 'F', 'text' => '北京市'], ], ]); ``` ```php $selectLink->route($route); ``` 连接开始: ```php $selectLink->start(); ``` 连接中: ```php $selectLink->through(); ``` 连接结束: ```php $selectLink->end(); ``` 设置禁用项: ```php $selectLink->disabled([ 'A', 'D', ]); ``` 设置控件标签: ```php $selectLink->label('下拉选择'); ``` 设置占位提示: ```php $selectLink->placeholder('请选择'); ``` 设置默认值: ```php $selectLink->defaultValue('B'); ``` 设置为必填: ```php $selectLink->required(true); ``` 设置注释文本: ```php $selectLink->comment('这里是一个注释文本'); ``` 设置栅栏布局 (默认:12`): ```php $selectLink->layout(6); ``` 设置ui类: ```php $selectLink->uiClass(['f13']); ``` 设置style样式: ```php $selectLink->style(); ``` 设置html属性: ```php $selectLink->attribute(); ``` ### 链式调用 ~~~ $formBuilder->setFormControl([ '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(), ]) ~~~ ### 代码示例 ~~~ /** * @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(); } } ~~~