Skip to content

Commit 3b0b8d0

Browse files
authored
feat:不允许可重复添加同一field的表单项 (#2923)
1 parent b30270a commit 3b0b8d0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/components/Form/src/hooks/useFormEvents.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,13 @@ export function useFormEvents({
210210
first = false,
211211
) {
212212
const schemaList: FormSchema[] = cloneDeep(unref(getSchema));
213-
213+
const addSchemaIds: string[] = Array.isArray(schema)
214+
? schema.map((item) => item.field)
215+
: [schema.field];
216+
if (schemaList.find((item) => addSchemaIds.includes(item.field))) {
217+
error('There are schemas that have already been added');
218+
return;
219+
}
214220
const index = schemaList.findIndex((schema) => schema.field === prefixField);
215221
const _schemaList = isObject(schema) ? [schema as FormSchema] : (schema as FormSchema[]);
216222
if (!prefixField || index === -1 || first) {

0 commit comments

Comments
 (0)