-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reset form validation #55
Comments
Check the available methods on the errors bag object you can use you would use it like this:
|
I used this.errors.clear() Tks |
this doesnt work for me... self.errors.clear(); |
When i use data() {
return {
user: {
email: ''
}
};
},
methods: {
reset() {
this.user = {
email: ''
};
this.$validator.clean();
}
} If i don't want to reset data values just vee-validate error messages, then i use: this.errors.clear(); |
@xereda Hello how did u clear the form errors upon closing the modal?? I've tried different methods of clear but it doesnt work |
According to the doc
Like this |
I've found it useful to put the reset in this.$validator.reset()
this.formFields.email = null
this.$validator.reset()
this.formFields.email = null
this.$nextTick(() => this.$validator.reset())
|
Shouldn't this be opened ? Doing IMHO, it seems like Anyway, I put a comment in the code with this issue for my coworkers. If you're reading this, this is the solution for now ! :) |
@romualdr the way I look at it is that If you want a one-line reset, you could create a method (or mixin for reuse) that "resets" the form fields (using Vue's reactivity to populate All that said, the documentation could use an explanation like this, or at least mention that race conditions can happen if programmatically updating form field values that use |
@bjunc Makes sense, i understand, thank you for answering. 👍 for the documentation "tip/warning" |
for anyone else interested here is my nuke: clearNewShow() {
this.formValues = {...blankForm}
this.dates = {start: '', end: ''}
this.$validator.pause()
this.$nextTick(() => {
this.$validator.errors.clear()
this.$validator.fields.items.forEach(field => field.reset())
this.$validator.fields.items.forEach(field => this.errors.remove(field))
this.$validator.resume()
})
} |
You saved my time @makslevental, thanks ! I'm currently using nuxt (SSR) and this is the only working solution I found. Here is my version (I didn't need reseting $validator.fields.items.forEach..., and I'm using v-form as well) try {
const { data } = await this.form.post('/api/contact').then(() => {
this.$validator.pause()
this.$nextTick(() => {
this.form.clear()
this.form.reset()
this.$validator.reset()
this.$validator.errors.clear()
this.$validator.resume()
})
})
} catch (e) {
this.$validator.validateAll()
} |
@makslevental solutions works, but not if data-vv-delay is used, then a setTimeout function needs to be used with same delay as the data-vv-delay value |
@nivv in the next tag coming up soon, the ongoing validations will be canceled if the validator |
After testing too many solutions, this worked for me: this.form.name = '';
this.form.email = '';
this.$nextTick(() => {
this.errors.clear();
this.$nextTick(() => {
this.$validator.reset();
});
}); |
@logaretm that saved my day. thank you |
this work for me:
|
If anyone finds this, now the way to do it is like explained in the docs (https://logaretm.github.io/vee-validate/guide/forms.html#resetting-forms) accessing with refs: <ValidationObserver ref="form">...</ValidationObserver> methods: {
onSubmit () {
// Resetting Values
this.firstName = this.lastName = this.email = '';
// Wait until the models are updated in the UI
this.$nextTick(() => {
this.$refs.form.reset();
});
}
} |
Hello,
How do I reset errors in my form? I have a modal window and when reopen, I disregard the previous mistakes.
What do you advise today with vee-validate?
Thank you.
The text was updated successfully, but these errors were encountered: