Skip to content

Commit 27b258c

Browse files
authored
fix(useForm): immdiate validate doesn't work (#4646)
1 parent 3b8b19e commit 27b258c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

components/form/useForm.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,20 @@ function useForm(
332332
return info;
333333
};
334334
let oldModel = initialModel;
335+
let isFirstTime = true;
335336
const modelFn = (model: { [x: string]: any }) => {
336337
const names = [];
337338
rulesKeys.value.forEach(key => {
338339
const prop = getPropByPath(model, key, false);
339340
const oldProp = getPropByPath(oldModel, key, false);
340-
if (!isEqual(prop.v, oldProp.v)) {
341+
const isFirstValidation = isFirstTime && options?.immediate && prop.isValid;
342+
343+
if (isFirstValidation || !isEqual(prop.v, oldProp.v)) {
341344
names.push(key);
342345
}
343346
});
344347
validate(names, { trigger: 'change' });
348+
isFirstTime = false;
345349
oldModel = cloneDeep(model);
346350
};
347351

0 commit comments

Comments
 (0)