From 9ca7cfc0d37cca9ba8c0c694e326204876142f29 Mon Sep 17 00:00:00 2001 From: Christel Westerberg Date: Mon, 24 Nov 2025 08:36:17 +0000 Subject: [PATCH] Merged in fix/STAY-15-validation-messages (pull request #3203) fix: Show correct validation errors in additionalInfoForm * fix: Show correct validation errors in additionalInfoForm Approved-by: Bianca Widstam Approved-by: Erik Tiekstra --- .../HotelReservation/FindMyBooking/AdditionalInfoForm.tsx | 1 + .../components/HotelReservation/FindMyBooking/schema.ts | 7 ++++++- .../components/TempDesignSystem/Form/Input/index.tsx | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/scandic-web/components/HotelReservation/FindMyBooking/AdditionalInfoForm.tsx b/apps/scandic-web/components/HotelReservation/FindMyBooking/AdditionalInfoForm.tsx index c35295de3..8b27e5c73 100644 --- a/apps/scandic-web/components/HotelReservation/FindMyBooking/AdditionalInfoForm.tsx +++ b/apps/scandic-web/components/HotelReservation/FindMyBooking/AdditionalInfoForm.tsx @@ -31,6 +31,7 @@ export default function AdditionalInfoForm({ const intl = useIntl() const form = useForm({ resolver: zodResolver(additionalInfoFormSchema), + defaultValues: { firstName: "", email: "" }, mode: "all", criteriaMode: "all", reValidateMode: "onChange", diff --git a/apps/scandic-web/components/HotelReservation/FindMyBooking/schema.ts b/apps/scandic-web/components/HotelReservation/FindMyBooking/schema.ts index e9bc192eb..6f980a86a 100644 --- a/apps/scandic-web/components/HotelReservation/FindMyBooking/schema.ts +++ b/apps/scandic-web/components/HotelReservation/FindMyBooking/schema.ts @@ -13,6 +13,7 @@ const findMyBookingErrors = { BOOKING_NUMBER_REQUIRED: "BOOKING_NUMBER_REQUIRED", FIRST_NAME_REQUIRED: "FIRST_NAME_REQUIRED", LAST_NAME_REQUIRED: "LAST_NAME_REQUIRED", + EMAIL_INVALID: "EMAIL_INVALID", EMAIL_REQUIRED: "EMAIL_REQUIRED", } as const @@ -22,7 +23,11 @@ const additionalInfoFormSchema = z.object({ .trim() .max(250) .min(1, findMyBookingErrors.FIRST_NAME_REQUIRED), - email: z.string().max(250).email(findMyBookingErrors.EMAIL_REQUIRED), + email: z + .string() + .max(250) + .min(1, findMyBookingErrors.EMAIL_REQUIRED) + .email(findMyBookingErrors.EMAIL_INVALID), }) const findMyBookingFormSchema = additionalInfoFormSchema.extend({ diff --git a/apps/scandic-web/components/TempDesignSystem/Form/Input/index.tsx b/apps/scandic-web/components/TempDesignSystem/Form/Input/index.tsx index edf8f0c4b..0680b0358 100644 --- a/apps/scandic-web/components/TempDesignSystem/Form/Input/index.tsx +++ b/apps/scandic-web/components/TempDesignSystem/Form/Input/index.tsx @@ -36,7 +36,7 @@ const Input = forwardRef(function Input( ref ) { const intl = useIntl() - const { control, formState } = useFormContext() + const { control } = useFormContext() const numberAttributes: HTMLAttributes = {} if (type === "number") { numberAttributes.onWheel = function (evt: WheelEvent) { @@ -50,7 +50,7 @@ const Input = forwardRef(function Input( control={control} name={name} rules={registerOptions} - render={({ field, fieldState }) => ( + render={({ field, fieldState, formState }) => (