From 6576b1144de90a14927167481c5d7bcc72cbddf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A1=E5=B1=B1=E7=94=B5=E8=BD=A6?= Date: Sun, 12 Sep 2021 15:14:10 +0800 Subject: [PATCH] fix(useForm): immdiate validate doesn't work --- components/form/useForm.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/form/useForm.ts b/components/form/useForm.ts index 75983d5eae..a6ebaa99a7 100644 --- a/components/form/useForm.ts +++ b/components/form/useForm.ts @@ -332,16 +332,20 @@ function useForm( return info; }; let oldModel = initialModel; + let isFirstTime = true; const modelFn = (model: { [x: string]: any }) => { const names = []; rulesKeys.value.forEach(key => { const prop = getPropByPath(model, key, false); const oldProp = getPropByPath(oldModel, key, false); - if (!isEqual(prop.v, oldProp.v)) { + const isFirstValidation = isFirstTime && options?.immediate && prop.isValid; + + if (isFirstValidation || !isEqual(prop.v, oldProp.v)) { names.push(key); } }); validate(names, { trigger: 'change' }); + isFirstTime = false; oldModel = cloneDeep(model); };