Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

How can I make a field required based in other field value with Zod?

$
0
0

I'm trying to validate a form with Zod and react-hook-form, and I need to make some fields required based on the value of other field. Here is my schema:

const formSchema = z.object({    cli_rut: z.string(),    cli_persona_natural: z.enum(["SI", "NO"]),    cli_nombres: z.string().optional(),    cli_apellido_paterno: z.string().optional(),    cli_apellido_materno: z.string().optional(),    cli_razon_social: z.string().optional(),    cli_estado: z.string().default("ACTIVO").optional(),});

in this case I need to make required cli_nombres, cli_apellido_materno, and cli_apellido_paterno if cli_persona_natural = "SI", any ideas of how can i do it? Thanks

I'm expecting the fields to be required if cli_persona_natural is "SI"


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>