Skip to content

Commit 3228d8d

Browse files
Vansh5632anikdhabalUdit-takkar
authored
refactor: A improvement fix related to optional phone validation (calcom#22305)
* fix:A bug related to optional phone validation * remove comment * fix: updated phone validation --------- Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
1 parent 6b9115d commit 3228d8d

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

packages/features/bookings/lib/getBookingResponsesSchema.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,14 @@ function preprocess<T extends z.ZodType>({
276276
}
277277

278278
if (bookingField.type === "phone") {
279-
if (!bookingField.hidden && !(await phoneSchema.safeParseAsync(value)).success) {
280-
ctx.addIssue({ code: z.ZodIssueCode.custom, message: m("invalid_number") });
279+
// Determine if the phone field needs validation
280+
const needsValidation = isRequired || (value && value.trim() !== "");
281+
282+
// Validate phone number if the field is not hidden and requires validation
283+
if (!bookingField.hidden && needsValidation) {
284+
if (!(await phoneSchema.safeParseAsync(value)).success) {
285+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: m("invalid_number") });
286+
}
281287
}
282288
continue;
283289
}

0 commit comments

Comments
 (0)