Skip to content

Commit

Permalink
fix: reset field should not validate closes #4323
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Jun 23, 2023
1 parent fc41691 commit 273cca7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/soft-chicken-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vee-validate': patch
---

fix: reset field should not validate closes #4323
2 changes: 1 addition & 1 deletion packages/vee-validate/src/useFieldState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export function _useFieldValue<TValue = unknown>(
return getFromPath<TValue>(form.values, unref(path)) as TValue;
},
set(newVal) {
form.setFieldValue(unref(path), newVal);
form.setFieldValue(unref(path), newVal, false);
},
}) as Ref<TValue>;

Expand Down
21 changes: 21 additions & 0 deletions packages/vee-validate/tests/useField.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -917,4 +917,25 @@ describe('useField()', () => {
expect(field.errors.value).toHaveLength(2);
expect(field.errors.value).toEqual([REQUIRED_MESSAGE, 'second']);
});

// #4323
test('resetField should not validate', async () => {
let field!: FieldContext;
const validator = vi.fn(val => (val ? true : REQUIRED_MESSAGE));

mountWithHoc({
setup() {
useForm();
field = useField('field', validator);

return {};
},
});

await flushPromises();
expect(field.errors.value).toHaveLength(0);
field.resetField({ value: '' });
await flushPromises();
expect(field.errors.value).toHaveLength(0);
});
});

0 comments on commit 273cca7

Please sign in to comment.