simple-vue-validator
simple-vue-validator copied to clipboard
Why overwritten async validations always succeeds
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
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.
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?