Skip to content

Commit 56206de

Browse files
committed
fix: clear out initial values for unregistered fields closes #3060
1 parent 4784e30 commit 56206de

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

packages/vee-validate/src/useForm.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ export function useForm<TValues extends Record<string, any> = Record<string, any
8888
});
8989

9090
// initial form values
91-
const { initialValues, setInitialValues } = useFormInitialValues<TValues>(
91+
const { readonlyInitialValues, initialValues, setInitialValues } = useFormInitialValues<TValues>(
9292
fieldsById,
9393
formValues,
9494
opts?.initialValues
9595
);
9696

9797
// form meta aggregations
98-
const meta = useFormMeta(fields, initialValues);
98+
const meta = useFormMeta(fields, readonlyInitialValues);
9999

100100
/**
101101
* Manually sets an error message on a specific field
@@ -283,6 +283,7 @@ export function useForm<TValues extends Record<string, any> = Record<string, any
283283
// so remove the field value key immediately
284284
if (field.idx === -1) {
285285
unsetPath(formValues, fieldName);
286+
unsetPath(initialValues.value, fieldName);
286287
return;
287288
}
288289

@@ -305,6 +306,7 @@ export function useForm<TValues extends Record<string, any> = Record<string, any
305306
}
306307

307308
unsetPath(formValues, fieldName);
309+
unsetPath(initialValues.value, fieldName);
308310
}
309311

310312
async function validate(): Promise<FormValidationResult<TValues>> {
@@ -616,7 +618,8 @@ function useFormInitialValues<TValues extends Record<string, any>>(
616618
provide(FormInitialValuesSymbol, computedInitials);
617619

618620
return {
619-
initialValues: computedInitials,
621+
readonlyInitialValues: computedInitials,
622+
initialValues,
620623
setInitialValues,
621624
};
622625
}

0 commit comments

Comments
 (0)