组件说明
组合表单组件用于组合多个表单项,支持动态增删、拖拽排序等功能。
用法示例
use plugin\xbCode\builder\Builder;
use plugin\xbCode\builder\Renders\Form;
Builder::form(function (Form $builder) {
// 创建联系人表单项
$nameInput = $builder->addRowInput('name', '姓名');
$phoneInput = $builder->addRowInput('phone', '电话');
$emailInput = $builder->addRowEmailInput('email', '邮箱');
// 组合多个表单项
$builder->addRowCombo('contacts', '联系人', [], [$nameInput, $phoneInput, $emailInput], function($component) {
$component->multiple(true); // 允许多条
$component->addable(true);
$component->removable(true);
$component->draggable(true);
$component->minLength(1);
$component->maxLength(5);
});
// 使用数组配置
$items = [
['type' => 'input-text', 'name' => 'title', 'label' => '标题'],
['type' => 'textarea', 'name' => 'content', 'label' => '内容']
];
$builder->addRowCombo('articles', '文章列表', [], $items, [
'multiple' => true,
'multiLine' => true, // 竖着展示
'addButtonText' => '添加文章',
'scaffold' => ['title' => '', 'content' => ''] // 默认值
]);
});
组件参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| name | string | - | 字段名称 |
| label | string | - | 字段标签 |
| value | array | [] | 默认值 |
| items | array | [] | 组合展示的表单项数组 |
| formClassName | string | - | 单组表单项的类名 |
| itemsColumnClassName | string | - | 列的类名,可配置列宽度 |
| itemsUnique | bool | false | 当前列值是否唯一,不允许重复选择 |
| noBorder | bool | false | 单组表单项是否显示边框 |
| scaffold | array | - | 单组表单项初始值 |
| multiple | bool | false | 是否多选 |
| multiLine | bool | false | 是否竖着展示(默认横着一排) |
| minLength | int | - | 最少添加的条数 |
| maxLength | int | - | 最多添加的条数 |
| flat | bool | false | 是否将结果扁平化 |
| joinValues | bool | true | 扁平化时是否用分隔符发送 |
| delimiter | string | ',' | 分隔符 |
| addable | bool | true | 是否可新增 |
| addattop | bool | false | 是否在顶部添加 |
| removable | bool | true | 是否可删除 |
| deleteApi | string | - | 删除前发送的API |
| deleteConfirmText | string | - | 删除确认文字 |
| draggable | bool | false | 是否可以拖动排序 |
| draggableTip | string | - | 可拖拽的提示文字 |
| subFormMode | string | 'normal' | 可选:normal、horizontal、inline |
| subFormHorizontal | array | - | horizontal模式时label占比 |
| placeholder | string | - | 没有成员时显示的文字 |
| addButtonText | string | '新增' | 新增按钮文字 |
| addButtonClassName | string | - | 新增按钮CSS类名 |
| itemClassName | string | - | 单组CSS类 |
| itemsWrapperClassName | string | - | 组合区域CSS类 |
使用说明
- items数组包含要组合的表单项配置
- multiple为true时可以添加多条记录
- multiLine控制表单项是横向还是纵向排列
- scaffold设置新增时的默认值
- flat为true且items长度为1时,可以扁平化数据结构
- 支持拖拽排序、最小最大数量限制等功能