优化FormBuilder对Form.List支持

master
LiuJiaNan 2025-12-03 08:39:54 +08:00
parent b7758526de
commit 23b7e1beab
2 changed files with 5 additions and 6 deletions

View File

@ -52,7 +52,7 @@ export interface FormListUniqueProps {
/** 删除按钮的文本,默认 '删除' */ /** 删除按钮的文本,默认 '删除' */
removeButtonText?: string; removeButtonText?: string;
/** 表单配置项 */ /** 表单配置项 */
options: FormOption[] | ((field: FormListFieldData) => FormOption[]); options: (field: FormListFieldData) => FormOption[];
/** 点击新增按钮时的默认值 */ /** 点击新增按钮时的默认值 */
addDefaultValue?: FormValues; addDefaultValue?: FormValues;
/** 点击新增按钮时插入的索引位置 */ /** 点击新增按钮时插入的索引位置 */

View File

@ -385,14 +385,14 @@ const FormItemsRenderer = ({
}; };
// 渲染普通表单项 // 渲染普通表单项
const renderFormItem = ({ option, style, col, index, name }) => { const renderFormItem = ({ option, style, col, index }) => {
if (getHidden(option.hidden)) if (getHidden(option.hidden))
return null; return null;
return ( return (
<Col key={getKey(option) || index} span={col.span} style={style}> <Col key={getKey(option) || index} span={col.span} style={style}>
<Form.Item <Form.Item
name={name || option.name} name={option.name}
label={renderLabel(option)} label={renderLabel(option)}
rules={getRules(option)} rules={getRules(option)}
labelCol={col.labelCol} labelCol={col.labelCol}
@ -407,7 +407,7 @@ const FormItemsRenderer = ({
}; };
// 渲染特殊类型的表单项 // 渲染特殊类型的表单项
const renderOtherTypeItem = ({ option, style, col, index, name }) => { const renderOtherTypeItem = ({ option, style, col, index }) => {
// 如果是 customizeRender 类型,完全交给外部控制渲染 // 如果是 customizeRender 类型,完全交给外部控制渲染
if (option.customizeRender) { if (option.customizeRender) {
return ( return (
@ -422,7 +422,7 @@ const FormItemsRenderer = ({
return ( return (
<Form.Item <Form.Item
key={getKey(option) || index} key={getKey(option) || index}
name={name || option.name} name={option.name}
noStyle noStyle
preserve={false} preserve={false}
> >
@ -463,7 +463,6 @@ const FormItemsRenderer = ({
style, style,
col, col,
index: `${fieldIndex}_${listIndex}`, index: `${fieldIndex}_${listIndex}`,
name: [field.name, listOption.name],
}; };
const otherTypeItem = renderOtherTypeItem(params); const otherTypeItem = renderOtherTypeItem(params);
if (otherTypeItem) if (otherTypeItem)