#Working with multiple checkboxes in Nextjs14, zod, shadcn/ui and react-hook-form.

6 messages · Page 1 of 1 (latest)

rapid spireBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

leaden osprey
#

You need to be A LOT more specific on the requirements...

Here are some following questions:

  1. Is that mean the checkbox(s) is a mandatory field? i.e. at least one checkbox must be checked?
  2. Are the checkboxes, if multiple, belong to the same "question" in the form? e.g. Which color do you like? (1) red, (2) green, (3) blue?
flat fossil
#

yes at least one checkbox must be checked and they all belong to the same question

leaden osprey
#

Then the zod schema should be something like:

checkboxes: z.string().array().min(1)

Replace "checkboxes" with some thing more meaningful in your case.

string() can be replaced with something else depending on the values of the checkbox

flat fossil
#

saw this example on shadcn's website:

        .array(z.string())
        .refine((value) => value.some((agent) => agent), {
            message: "You have to select at least one item.",
        }),```
#

it seems to be wokring now