Because the validateAll methods throws an exception, I'm forced to have .catch(() => { }) littered through my code otherwise the exception isn't caught and I get an uncaught error. The exception isn't interesting to me because the error messages are rendered in my template automatically using the errorBag. I shouldn't be forced to deal with this error.
The purpose of this method is to validate all fields. It should only throw an exception if there was an unexpected problem when trying to run validation. A field not being valid isn't an error. it's an expected outcome. So why are people forced to have a (possibly empty) catch block in there code for expected outcomes?
Because its a promise based validation, should you use then for all cases and check the result, I don't think that is better.
What I can do is provide an option to handle thrown calls, so it would catch it for you.
Yes, that is what you should do. Why shouldn't you do it that way?
For the users who don't do anything in the catch callback, your argument is valid, for those who want to do other things, why should they check the result each time so to them the current behavior is reasonable.
Regardless of use case we can just provide an option when installing the plugin, so I think that is a fair way to handle both cases.
Something like this:
Vue.use(VeeValidate, {
softRejct: true
});
By default it would be false, so the users should catch their calls, otherwise they can just set the option and don't catch it.
Okay, if that's the way you want to go, then I don't have an issue. But here is a counter example to the point you just raised.
Lets say I have a catch block to do something when validation fails (an expected outcome). Instead of just doing
.then((result) => {
if (result === false) {
// Validation errors
}
})
You now need to actually inspect the exception and check it is an expected exception rather than an unexpected one. Put another way, you need to check if there is a real error happening or a fake error. It seems like there is no less work to with a catch block. But forcing people to have a catch block make them do more work.
Like I said, I think your solution is fine. But I think using exceptions for expected outcomes of running validation is an anti-pattern. It masks real errors.
I'm convinced 😄 , you are right about the issue with masking, it would make debugging faulty rules or future changes harder.
validateForm(scope) {
this.$validator.validateAll(scope)
.then(() => {
alert('success')
})
.catch(() => { })
}
Hi @logaretm why i get this error when i'm handling my promises?
@pachecoder Sorry I didn't see your comment, does it still occur with version rc.6?
Closing since rc.6 is released sometime ago ...
@logaretm Sorry, my problem was gone, i uninstall vee-validate, later run this command:
npm install vee-validate@prev --save --force.
I think was the deprecated version of the package.
prev tag installs Vue 1.0 version, which is the deprecated version indeed. glad it worked.
@rstuart85 @logaretm
Since validateAll() returns a promise, couldn't we use .done() and .fail() or would that present the same problem that caused you to get rid of .catch()?