fastest-validator
fastest-validator copied to clipboard
Halt on Error Possible?
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.
It's not available currently.
Hello, I would like to implement this. If you have any clues to get started, it would be welcome.
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.
Thank you @icebob. I will start working on this.