diff --git a/components/form/useForm.ts b/components/form/useForm.ts index e168b69de..07e3281cb 100644 --- a/components/form/useForm.ts +++ b/components/form/useForm.ts @@ -119,19 +119,33 @@ function useForm( clearValidate: (names?: namesType) => void; } { const initialModel = cloneDeep(unref(modelRef)); - let validateInfos: validateInfos = {}; + const validateInfos = reactive({}); const rulesKeys = computed(() => { return Object.keys(unref(rulesRef)); }); - rulesKeys.value.forEach(key => { - validateInfos[key] = { - autoLink: false, - required: isRequired(unref(rulesRef)[key]), - }; - }); - validateInfos = reactive(validateInfos); + watch( + rulesKeys, + () => { + const newValidateInfos = {}; + rulesKeys.value.forEach(key => { + newValidateInfos[key] = validateInfos[key] || { + autoLink: false, + required: isRequired(unref(rulesRef)[key]), + }; + delete validateInfos[key]; + }); + for (const key in validateInfos) { + if (Object.prototype.hasOwnProperty.call(validateInfos, key)) { + delete validateInfos[key]; + } + } + Object.assign(validateInfos, newValidateInfos); + }, + { immediate: true }, + ); + const resetFields = (newValues: Props) => { Object.assign(unref(modelRef), { ...cloneDeep(initialModel), @@ -251,6 +265,9 @@ function useForm( }, !!option.validateFirst, ); + if (!validateInfos[name]) { + return promise.catch((e: any) => e); + } validateInfos[name].validateStatus = 'validating'; promise .catch((e: any) => e) @@ -327,7 +344,9 @@ function useForm( validate(names, { trigger: 'change' }); oldModel = cloneDeep(model); }; + const debounceOptions = options?.debounce; + watch( modelRef, debounceOptions && debounceOptions.wait diff --git a/v2-doc b/v2-doc index 2e39bc81a..3f94a02d1 160000 --- a/v2-doc +++ b/v2-doc @@ -1 +1 @@ -Subproject commit 2e39bc81a84e2cfa90e8863e8f18d5a3d3ab1995 +Subproject commit 3f94a02d16bac2377d71e26948ffe45571dae49e