Vee-validate 4 + Vue 3 - form.reset() does not clear form fields
See original GitHub issueI apologise if this should not have been opened due to Vee-validate 4’s beta status!
Versions
- vee-validate: 4.0.0-beta.16
- vue: 3.0.2
Describe the bug
Within a custom Vue 3 SFC using Vee-validate’s Form and Field components, I have a @submit listener attached to the Form component which calls the ‘onSubmit’ method. Within this method, is the call form.reset() to clear fields, as per the documentation, of any values at submission. This does not appear to be functioning as expected. Nothing appears within the console log when this action occurs.
Expected behavior Once the form is submitted, expected to see form’s input fields cleared from all input.
Desktop (please complete the following information):
- OS: macOS 10.15.7
- Browser: Chrome
- Version: 86.0.4240.111
Additional context
Form
<VeeForm @submit="onSubmit" :validation-schema="schema.validation" :initial-values="schema.values" >
Button
<BaseButton buttonType="submit">Submit</BaseButton>
Method
methods: { onSubmit(values, { form }) { let formValues = {} for (const [key, value] of Object.entries(values)) { formValues = { ...formValues, [key]: value.trim() } } this.$emit('form-values', formValues) form.reset() }
I also attempted to achieve the same using this.$refs... but got the same result.
Link to documentation: https://vee-validate.logaretm.com/v4/guide/handling-forms#resetting-forms-after-submit
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Related StackOverflow Question
@matthewlynden Heads up, a new reset API was implemented and is now available on
beta.19It contains breaking changes but overall an improved API and resets the values as well without having to explicitly call
setValues.Your previous code snippet would work fine but with these changes:
resetdoes not change the input values, this is by design, you will need to change them withsetValuesthen trigger the reset.Looks like the documentation wasn’t updated to reflect that, will fix that promptly.
If I think of a better API to automatically reset the values with
resetcalls I will update this issue.