提交表单后如何重置验证?
How to reset validation after submitting form?
表单提交成功后,会显示验证信息。
浏览器:火狐浏览器
this.user = {
branch: '',
department: '',
designation: '',
mobile: '+91 ',
}
this.$validator.reset()
this.errors.clear();
上述代码用于成功后重置表单。
基于 this issue,我相信适合您的解决方案如下:
const blankForm = {
branch: '',
department: '',
designation: '',
mobile: '+91 '
}
clearNewShow() {
this.formValues = {...blankForm}
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()
})
}
表单提交成功后,会显示验证信息。
浏览器:火狐浏览器
this.user = {
branch: '',
department: '',
designation: '',
mobile: '+91 ',
}
this.$validator.reset()
this.errors.clear();
上述代码用于成功后重置表单。
基于 this issue,我相信适合您的解决方案如下:
const blankForm = {
branch: '',
department: '',
designation: '',
mobile: '+91 '
}
clearNewShow() {
this.formValues = {...blankForm}
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()
})
}