fix(useForm): immdiate validate doesn't work (#4646)
parent
3b8b19ea8c
commit
27b258c29b
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue