Skip to content

Commit

Permalink
feat(component): 不允许可重复添加同一field的表单项
Browse files Browse the repository at this point in the history
  • Loading branch information
xingyuv committed Jul 26, 2023
1 parent 56ddd76 commit f33c82f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/components/Form/src/hooks/useFormEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ export function useFormEvents({
) {
const schemaList: FormSchema[] = cloneDeep(unref(getSchema));

const addSchemaIds: string[] = Array.isArray(schema)
? schema.map((item) => item.field)
: [schema.field];
if (schemaList.find((item) => addSchemaIds.includes(item.field))) {
error('There are schemas that have already been added');
return;
}

const index = schemaList.findIndex((schema) => schema.field === prefixField);
const _schemaList = isObject(schema) ? [schema as FormSchema] : (schema as FormSchema[]);
if (!prefixField || index === -1 || first) {
Expand Down

0 comments on commit f33c82f

Please sign in to comment.