fix(useForm): immdiate validate doesn't work (#4646)

pull/4642/head
叡山电车 2021-09-15 15:14:46 +08:00 committed by GitHub
parent 3b8b19ea8c
commit 27b258c29b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -332,16 +332,20 @@ function useForm(
return info; return info;
}; };
let oldModel = initialModel; let oldModel = initialModel;
let isFirstTime = true;
const modelFn = (model: { [x: string]: any }) => { const modelFn = (model: { [x: string]: any }) => {
const names = []; const names = [];
rulesKeys.value.forEach(key => { rulesKeys.value.forEach(key => {
const prop = getPropByPath(model, key, false); const prop = getPropByPath(model, key, false);
const oldProp = getPropByPath(oldModel, 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); names.push(key);
} }
}); });
validate(names, { trigger: 'change' }); validate(names, { trigger: 'change' });
isFirstTime = false;
oldModel = cloneDeep(model); oldModel = cloneDeep(model);
}; };