fix(amis-saas-6852): 完善表单脚手架,分组中单选和复选框自动补全options

Change-Id: I3924cf6c343f42a6d5382ab04a864e046014c10c
This commit is contained in:
wibetter 2022-11-29 20:08:37 +08:00
parent 398cdef083
commit 882a1a957a

View File

@ -95,6 +95,28 @@ const formItemOptions = [
}
];
// 自动为form中子元素单选框、复选框补上默认options
const autoAddOptions = (values: any) => {
if (values && (values.type === 'form' || values.type === 'group') && values.body?.length > 0) {
values.body.forEach((formItem: any) => {
if (formItem.type === 'radios' || formItem.type === 'checkboxes') {
formItem.options = [
{
label: "选项A",
value: "A"
},
{
label: "选项B",
value: "B"
}
];
} else if (formItem.type === 'form' || formItem.type === 'group') {
autoAddOptions(formItem);
}
});
}
}
export class FormPlugin extends BasePlugin {
// 关联渲染器名字
rendererName = 'form';
@ -184,23 +206,7 @@ export class FormPlugin extends BasePlugin {
}
],
pipeOut: (values: any) => {
// 给form中直接子元素单选框、复选框自动添加上默认options
if (values && values.type === 'form' && values.body?.length > 0) {
values.body.forEach((formItem: any) => {
if (formItem.type === 'radios' || formItem.type === 'checkboxes') {
formItem.options = [
{
label: "选项A",
value: "A"
},
{
label: "选项B",
value: "B"
}
];
}
});
}
autoAddOptions(values);
return values;
}
};