diff --git a/src/uni_modules/wot-design-uni/components/wd-form/types.ts b/src/uni_modules/wot-design-uni/components/wd-form/types.ts index 176b14620..d93b490b9 100644 --- a/src/uni_modules/wot-design-uni/components/wd-form/types.ts +++ b/src/uni_modules/wot-design-uni/components/wd-form/types.ts @@ -35,7 +35,10 @@ export interface FormItemRule { required: boolean message: string pattern?: RegExp - validator?: (value: any, rule: FormItemRuleWithoutValidator) => boolean | Promise | Promise | Promise | Promise + validator?: ( + value: any, + rule: FormItemRuleWithoutValidator + ) => boolean | Promise | Promise | Promise | Promise | Promise } export type FormItemRuleWithoutValidator = Omit diff --git a/src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue b/src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue index 4e8232ade..3c9f87810 100644 --- a/src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue +++ b/src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue @@ -94,11 +94,23 @@ async function validate(prop?: string): Promise<{ valid: boolean; errors: ErrorM valid = false } }) - .catch((error) => { - errors.push({ - prop, - message: error || rule.message - }) + .catch((error: any) => { + if (error instanceof Error) { + errors.push({ + prop, + message: error.message || rule.message + }) + } else if (typeof error === 'string') { + errors.push({ + prop, + message: error + }) + } else { + errors.push({ + prop, + message: rule.message + }) + } valid = false }) )