Skip to content

Commit ecb540a

Browse files
committed
fix: handle getter field names properly closes #4877
1 parent 0991c01 commit ecb540a

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

.changeset/nice-chefs-stare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"vee-validate": patch
3+
---
4+
5+
fix: handle getter field names properly closes #4877

packages/vee-validate/src/useForm.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export function useForm<
193193
const errorBag = computed<FormErrorBag<TValues>>(() => {
194194
const pathErrors = pathStates.value.reduce((acc, state) => {
195195
if (state.errors.length) {
196-
acc[state.path as Path<TValues>] = state.errors;
196+
acc[toValue(state.path) as Path<TValues>] = state.errors;
197197
}
198198

199199
return acc;
@@ -220,7 +220,7 @@ export function useForm<
220220
const fieldNames = computed(() => {
221221
return pathStates.value.reduce(
222222
(names, state) => {
223-
names[state.path] = { name: state.path || '', label: state.label || '' };
223+
names[toValue(state.path)] = { name: toValue(state.path) || '', label: state.label || '' };
224224

225225
return names;
226226
},
@@ -231,7 +231,7 @@ export function useForm<
231231
const fieldBailsMap = computed(() => {
232232
return pathStates.value.reduce(
233233
(map, state) => {
234-
map[state.path] = state.bails ?? true;
234+
map[toValue(state.path)] = state.bails ?? true;
235235

236236
return map;
237237
},
@@ -259,8 +259,8 @@ export function useForm<
259259

260260
const controlledValues = computed(() => {
261261
return pathStates.value.reduce((acc, state) => {
262-
const value = getFromPath(formValues, state.path);
263-
setInPath(acc, state.path, value);
262+
const value = getFromPath(formValues, toValue(state.path));
263+
setInPath(acc, toValue(state.path), value);
264264

265265
return acc;
266266
}, {} as TValues);
@@ -480,7 +480,7 @@ export function useForm<
480480
}
481481

482482
function findHoistedPath(path: Path<TValues>) {
483-
const candidates = pathStates.value.filter(state => path.startsWith(state.path));
483+
const candidates = pathStates.value.filter(state => path.startsWith(toValue(state.path)));
484484

485485
return candidates.reduce(
486486
(bestCandidate, candidate) => {
@@ -833,10 +833,10 @@ export function useForm<
833833
mutateAllPathState(state => {
834834
state.__flags.pendingReset = true;
835835
state.validated = false;
836-
state.touched = resetState?.touched?.[state.path as Path<TValues>] || false;
836+
state.touched = resetState?.touched?.[toValue(state.path) as Path<TValues>] || false;
837837

838-
setFieldValue(state.path as Path<TValues>, getFromPath(newValues, state.path), false);
839-
setFieldError(state.path as Path<TValues>, undefined);
838+
setFieldValue(toValue(state.path) as Path<TValues>, getFromPath(newValues, toValue(state.path)), false);
839+
setFieldError(toValue(state.path) as Path<TValues>, undefined);
840840
});
841841

842842
opts?.force ? forceSetValues(newValues, false) : setValues(newValues, false);
@@ -868,7 +868,7 @@ export function useForm<
868868
pathStates.value.map(state => {
869869
if (!state.validate) {
870870
return Promise.resolve({
871-
key: state.path,
871+
key: toValue(state.path),
872872
valid: true,
873873
errors: [],
874874
value: undefined,
@@ -877,7 +877,7 @@ export function useForm<
877877

878878
return state.validate(opts).then(result => {
879879
return {
880-
key: state.path,
880+
key: toValue(state.path),
881881
valid: result.valid,
882882
errors: result.errors,
883883
value: result.value,
@@ -1060,15 +1060,15 @@ export function useForm<
10601060
pathState.touched = true;
10611061
const validateOnBlur = evalConfig().validateOnBlur ?? getConfig().validateOnBlur;
10621062
if (validateOnBlur) {
1063-
validateField(pathState.path as Path<TValues>);
1063+
validateField(toValue(pathState.path) as Path<TValues>);
10641064
}
10651065
}
10661066

10671067
function onInput() {
10681068
const validateOnInput = evalConfig().validateOnInput ?? getConfig().validateOnInput;
10691069
if (validateOnInput) {
10701070
nextTick(() => {
1071-
validateField(pathState.path as Path<TValues>);
1071+
validateField(toValue(pathState.path) as Path<TValues>);
10721072
});
10731073
}
10741074
}
@@ -1077,7 +1077,7 @@ export function useForm<
10771077
const validateOnChange = evalConfig().validateOnChange ?? getConfig().validateOnChange;
10781078
if (validateOnChange) {
10791079
nextTick(() => {
1080-
validateField(pathState.path as Path<TValues>);
1080+
validateField(toValue(pathState.path) as Path<TValues>);
10811081
});
10821082
}
10831083
}
@@ -1308,8 +1308,8 @@ function useFormInitialValues<TValues extends GenericObject>(
13081308
return;
13091309
}
13101310

1311-
const newValue = getFromPath(initialValues.value, state.path);
1312-
setInPath(formValues, state.path, deepCopy(newValue));
1311+
const newValue = getFromPath(initialValues.value, toValue(state.path));
1312+
setInPath(formValues, toValue(state.path), deepCopy(newValue));
13131313
});
13141314
}
13151315

0 commit comments

Comments
 (0)