kazupon / vue-validator

:white_check_mark: Validator component for Vue.js
MIT License
2.19k stars 431 forks source link

$resetValidation() does not work #315

Open z1haze opened 7 years ago

z1haze commented 7 years ago

I am trying to figure out how to reset a validator on my page? I am using vue-router, and I have the same component being used for 2 different routes, a create, and edit route. The component just shows a form, one route shows an empty form, one route shows a populated form.

My issue is that when i visit the /edit route that prepopulates the form, the next time i visit the /create route which has an empty form, its already showing validation errors, even though I havent touched it yet.

I tried using $this.resetValidation() in the route object's data function (that is fired everything the route is hit), but it does nothing. Please advise!

kazupon commented 7 years ago

sorry, for the late response. can you share the minimum reproduction code please?

z1haze commented 7 years ago

Inside the route object data function calling this.$resetValidation() sorry I'm on my phone but I believe that's was the gist of it

Sent from my iPhone, sorry about the typos.

On Sep 22, 2016, at 1:39 PM, kazuya kawaguchi notifications@github.com wrote:

sorry, for the late response. can you share the minimum reproduction code please?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

woodygithub commented 7 years ago

我也遇到了这个问题,弹出框第二次进入的时候我将数据清空,但是错误提示依然显示

woodygithub commented 7 years ago

BaseValidation.prototype.reset = function reset() { this.resetValidationNoopable(); this.resetFlags(); this._init = this._getValue(this._el); }; 查看源码发现BaseValidation的reset方法只重置了通用的flag,没有重置各个校验器的校验结果flag所以用来显示error的布尔值依然是上次校验的结果或者修改表单值触发校验的结果,现在我只能手动将所有值重置来恢复状态非常麻烦,希望能解决 `