From 11349b9b2b4c8bd76162fa741b88986ccfacc53e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B9=A4=E4=BB=99?= Date: Wed, 15 Jan 2025 14:56:12 +0800 Subject: [PATCH] feat(validateFields): add message to reject error type --- src/interface.ts | 1 + src/useForm.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/interface.ts b/src/interface.ts index 751ed3b4..482f6d09 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -86,6 +86,7 @@ export type RuleObject = AggregationRule | ArrayRule; export type Rule = RuleObject | RuleRender; export interface ValidateErrorEntity { + message: string; values: Values; errorFields: { name: InternalNamePath; errors: string[] }[]; outOfDate: boolean; diff --git a/src/useForm.ts b/src/useForm.ts index 7879cf85..d685635a 100644 --- a/src/useForm.ts +++ b/src/useForm.ts @@ -982,7 +982,9 @@ export class FormStore { }) .catch((results: { name: InternalNamePath; errors: string[] }[]) => { const errorList = results.filter(result => result && result.errors.length); + const errorMessage = errorList[0]?.errors?.[0]; return Promise.reject({ + message: errorMessage, values: this.getFieldsValue(namePathList), errorFields: errorList, outOfDate: this.lastValidatePromise !== summaryPromise,