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

Dependencies for nested fields #69

Open
imprakharshukla opened this issue Mar 27, 2024 · 1 comment
Open

Dependencies for nested fields #69

imprakharshukla opened this issue Mar 27, 2024 · 1 comment

Comments

@imprakharshukla
Copy link

Hey! I am trying to implement a rather complex form and would like to apply dependencies on nested fields. Here's a sample schema:

 inventory: z
    .array(
      z.object({
        size: z.enum([
          "XXS",
          "XS",
          "S",
          "M",
          "L",
          "XL",
          "XXL",
          "XXXL",
          "Free Size",
          "One Size",
          "Custom",
        ]),
        customSize: z.string().optional(),
        measurements: z.object({
          bust: z.number().optional(),
          waist: z.number().optional(),
        }),
        variant: z.array(
          z.object({
            name: z.string(),
            quantity: z.number(),
            price: z.number(),
          }),
        ),
      }),
    )

What i am trying to do is show and hide the custom size field depending upon the current value of the size select. The docs do not mention how to name the dependencies when dealing with nested fields.

Grateful for any help.

@vantezzen
Copy link
Owner

I don't know if the code correctly handles nesting but you can try using dot notation like "inventory.size" - otherwise I'd be happy to accept PRs to add this

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

No branches or pull requests

2 participants