simple-vue-validator icon indicating copy to clipboard operation
simple-vue-validator copied to clipboard

Why overwritten async validations always succeeds

Open sabob opened this issue 6 years ago • 2 comments
trafficstars

Hi all,

I know the project is dormant currently but perhaps someone might know why async validations that is "overwritten" by a second async call succeeds eg.

let success = await $validate() will return true if an async validation is triggered again before the original event completes.

If my explanation is a bit confusing the lines in question is here: https://github.com/semisleep/simple-vue-validator/blob/0ee438ef483041dca213859a9e385419f55a9db7/src/validation-bag.js#L238-L242

specifically line 242 returns false, meaning there is no error. Isn't it safer to return true rather?

Kind regards

Bob

sabob avatar Aug 09 '19 18:08 sabob

Hi there, if async $validate() is invoked again before the previous one completes, there's no way to guarantee that the result of the previous async $validate() is correct. This is because all $validate() invocations share the same ValidationBag, which can only hold the result of the latest $validate() state.

semisleep avatar Aug 10 '19 01:08 semisleep

Thanks for your response. Sounds we are saying the same thing and perhaps I misread the code but I think line 242 really says:

var hasError = false;
return hasError;

meaning $validate succeeds for the first call. Shouldn't it be:

var hasError = true;
return hasError;

so that the first request always fails and the second request will return an accurate response?

sabob avatar Aug 10 '19 09:08 sabob