Asynchronous validations
See original GitHub issueThere’s support for validating promise types, but I don’t see a way to create async validators.
What I’m thinking of is something like this:
const foreignKey = z.string().refine(idExistsAsync, {
message: "ID not found",
});
foreignKey.parseAsync("1234")
Where idExistsAsync
is some function that asynchronously checks some backend to make sure that the value is valid. It returns a promise. Of course this would mean that the entire schema becomes async, so there are some other concerns here when async values are used as fields on objects.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Asynchronous Validation — FluentValidation documentation
By default, FluentValidation allows custom rules defined with MustAsync or CustomAsync to be run asynchronously, as well as defining asynchronous conditions ...
Read more >Asynchronous validation - Ajv JSON schema validator
Asynchronous validation. You can define formats and keywords that perform validation asynchronously by accessing database or some other service.
Read more >Using Custom Async Validators in Angular Reactive Forms
In Angular, you can do this using Async Validators. Create a basic application. We are going to create a very minimalist form that...
Read more >yiminghe/async-validator: validate form asynchronous - GitHub
If your validation involves multiple asynchronous calls (for example, database queries) and you only need the first error use this option.
Read more >Async Validation In Angular - C# Corner
Rules for Async Validator · The function must implement the AsyncValidatorFn Interface, which defines the signature of the validator function.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is now available in the Zod 2 beta: https://github.com/vriad/zod/tree/v2
@chrbala @Albertbol
Thank you that’s awesome ! Will test it out