Commit 3b0b8d0baa9b03a82fb88fbdb4bb21214793dfe6
Committed by
GitHub
1 parent
b30270a3
feat:不允许可重复添加同一field的表单项 (#2923)
Showing
1 changed file
with
7 additions
and
1 deletions
src/components/Form/src/hooks/useFormEvents.ts
... | ... | @@ -210,7 +210,13 @@ export function useFormEvents({ |
210 | 210 | first = false, |
211 | 211 | ) { |
212 | 212 | 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 | + } | |
214 | 220 | const index = schemaList.findIndex((schema) => schema.field === prefixField); |
215 | 221 | const _schemaList = isObject(schema) ? [schema as FormSchema] : (schema as FormSchema[]); |
216 | 222 | if (!prefixField || index === -1 || first) { | ... | ... |