Skip to content

Commit

Permalink
fix(useForm): immdiate validate doesn't work (#4646)
Browse files Browse the repository at this point in the history
  • Loading branch information
ylc395 authored Sep 15, 2021
1 parent 3b8b19e commit 27b258c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion components/form/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down

0 comments on commit 27b258c

Please sign in to comment.