From 2572a5cb93e452861986a2526477a63a58dbb7df Mon Sep 17 00:00:00 2001 From: Ashutosh Sangwan Date: Mon, 16 Sep 2024 16:01:33 +0530 Subject: [PATCH] fixes multiselect required check (#16653) Co-authored-by: Ashutosh Sangwan Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> --- .../bookings/lib/getBookingResponsesSchema.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/features/bookings/lib/getBookingResponsesSchema.ts b/packages/features/bookings/lib/getBookingResponsesSchema.ts index 9e0a565b13..a2357ca243 100644 --- a/packages/features/bookings/lib/getBookingResponsesSchema.ts +++ b/packages/features/bookings/lib/getBookingResponsesSchema.ts @@ -217,7 +217,18 @@ function preprocess({ continue; } - if (bookingField.type === "checkbox" || bookingField.type === "multiselect") { + if (bookingField.type === "multiselect") { + if (isRequired && (!value || value.length === 0)) { + ctx.addIssue({ code: z.ZodIssueCode.custom, message: m(`error_required_field`) }); + continue; + } + if (!stringSchema.array().safeParse(value).success) { + ctx.addIssue({ code: z.ZodIssueCode.custom, message: m("Invalid array of strings") }); + } + continue; + } + + if (bookingField.type === "checkbox") { if (!stringSchema.array().safeParse(value).success) { ctx.addIssue({ code: z.ZodIssueCode.custom, message: m("Invalid array of strings") }); }