Skip to content

Commit fd008c1

Browse files
committedMay 29, 2024·
feat: added ResetFormOpts arg to useResetForm closes #4707
1 parent dadc58a commit fd008c1

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed
 

‎.changeset/wise-schools-hammer.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"vee-validate": patch
3+
---
4+
5+
feat: added ResetFormOpts arg to useResetForm closes #4707
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FormContextKey } from './symbols';
2-
import { FormState } from './types';
2+
import { FormState, ResetFormOpts } from './types';
33
import { injectWithSelf, warn } from './utils';
44

55
export function useResetForm<TValues extends Record<string, unknown> = Record<string, unknown>>() {
@@ -10,11 +10,11 @@ export function useResetForm<TValues extends Record<string, unknown> = Record<st
1010
}
1111
}
1212

13-
return function resetForm(state?: Partial<FormState<TValues>>) {
13+
return function resetForm(state?: Partial<FormState<TValues>>, opts?: ResetFormOpts) {
1414
if (!form) {
1515
return;
1616
}
1717

18-
return form.resetForm(state);
18+
return form.resetForm(state, opts);
1919
};
2020
}

‎packages/vee-validate/tests/useResetForm.spec.ts

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useField, useForm, useResetForm } from '@/vee-validate';
1+
import { FormContext, useField, useForm, useResetForm } from '@/vee-validate';
22
import { mountWithHoc, setValue, flushPromises } from './helpers';
33

44
describe('useResetForm()', () => {
@@ -73,4 +73,30 @@ describe('useResetForm()', () => {
7373
expect(spy).toHaveBeenCalled();
7474
spy.mockRestore();
7575
});
76+
77+
test('resets a form with passed options', async () => {
78+
let resetForm: any;
79+
let form!: FormContext<{ fname: string; lname: string }>;
80+
81+
mountWithHoc({
82+
setup() {
83+
form = useForm({
84+
initialValues: { fname: '123', lname: '456' },
85+
});
86+
87+
resetForm = useResetForm();
88+
89+
return {};
90+
},
91+
template: `
92+
<div></div>
93+
`,
94+
});
95+
96+
await flushPromises();
97+
98+
resetForm({ values: { fname: 'test' } }, { force: true });
99+
expect(form.values.lname).toBeUndefined();
100+
expect(form.values.fname).toBe('test');
101+
});
76102
});

0 commit comments

Comments
 (0)
Please sign in to comment.