fixes multiselect required check (#16653)

Co-authored-by: Ashutosh Sangwan <ashutoshsangwan@Ashutoshs-MacBook-Pro.local>
Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
This commit is contained in:
Ashutosh Sangwan
2024-09-16 10:31:33 +00:00
committed by GitHub
co-authored by Ashutosh Sangwan Anik Dhabal Babu
parent 45e0f87e45
commit 2572a5cb93
@@ -217,7 +217,18 @@ function preprocess<T extends z.ZodType>({
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") });
}