Zod
You may want to use Zod validator because:
- You can use Zod schema as a source of truth for the form value type (
z.infer
). - This is an easy way to add custom error messages
Installation
References:
Example
Caveats
-
If you using this library only for full form validation (without fields validation mode) and your form does not have and
oneOf
,anyOf
,dependencies
if
keywords or recursive references, you can use this library pretty safely. -
If you are using fields validation mode then starting from this point internally we start to use
json-schema-to-zod
. So first of all, please read this warning about using this library at runtime. However, I believe you are still safe as only small leafy bits of the circuit are transformed with this approach. -
If you use any conditional keyword or recursive references it means with a high probability something can go wrong. If you have problems with this approach, try using zod with a different validator using the
augment
submodule. So in this case zod validator will be used only for full form validation.
Async validation
This validator supports async validation but only for the full form validation.