fastest-validator icon indicating copy to clipboard operation
fastest-validator copied to clipboard

Halt on Error Possible?

Open blendPOS opened this issue 3 years ago • 1 comments

I don't see a way currently, but is it possible to halt the validation process as soon as a validator encounters an error? I'm using an async validator, and I'd like to be able to run basic validations (string length, format, etc), before accessing the DB (which are async custom validations in the same schema property).

If a field hits an error, I'd like the validation process to stop and return the single error instead of progressing throughout and returning additional errors as well.

blendPOS avatar Jul 18 '22 19:07 blendPOS

It's not available currently.

icebob avatar Aug 03 '22 16:08 icebob

Hello, I would like to implement this. If you have any clues to get started, it would be welcome.

avanelli avatar Aug 19 '22 07:08 avanelli

You should check the source code and check the generated codes as well (debug: true in options). I think the best solution to implement it in the object rule and checks the error array after every property and if it contains items return with the errors (if this new option (e.g. haltOnError is enabled).

The hardest part will be the multi rule, e.g. you have two object definitions in a multi rule but if the first is not valid you should not halt the processing because the second can be valid.

icebob avatar Aug 21 '22 14:08 icebob

Thank you @icebob. I will start working on this.

avanelli avatar Aug 23 '22 14:08 avanelli