Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to write async custom validators? #41

Open
kevinrood opened this issue Apr 7, 2018 · 3 comments
Open

Is it possible to write async custom validators? #41

kevinrood opened this issue Apr 7, 2018 · 3 comments

Comments

@kevinrood
Copy link

First of all, thanks for making validate available 😄

I could not determine from the readme whether it is possible to write async custom validators (a validator which relies on looking up a database record, for example). Is that possible?

@eivindfjeldstad
Copy link
Owner

No, not currently. For my use case it didn't make much sense because of concurrency issues etc. Do you have a specific use case in mind?

@kevinrood
Copy link
Author

It is fairly common in web apps I build to include database queries as a part of some validation rules.

Additionally, separate from async validation, object-level validation (validating a few fields together) is a common requirement.

@eivindfjeldstad
Copy link
Owner

Yeah, I do the same thing, but I like to delegate that stuff to the db layer to avoid race conditions.

You can validate fields together (sort of) by doing something like this:

const something = (val, ctx) => val > ctx.some.other.path;
schema.path('some.path').use({ something })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants