From b381289d451f9ea75879ccab892fa7db5adb4cde Mon Sep 17 00:00:00 2001 From: Dareenfadel Date: Fri, 8 Mar 2024 23:57:06 +0200 Subject: [PATCH] "Fix issue #7361: Block users from entering date out of range" --- src/Components/Common/DateInputV2.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Components/Common/DateInputV2.tsx b/src/Components/Common/DateInputV2.tsx index da974fbe0e9..bce5f24b11c 100644 --- a/src/Components/Common/DateInputV2.tsx +++ b/src/Components/Common/DateInputV2.tsx @@ -159,6 +159,22 @@ const DateInputV2: React.FC = ({ return true; }; + const isDateWithinLimits = (parsedDate: dayjs.Dayjs): boolean => { + if (parsedDate?.isValid()) { + if ( + (max && parsedDate.toDate() > max) || + (min && parsedDate.toDate() < min) + ) { + Notification.Error({ + msg: outOfLimitsErrorMessage ?? "Cannot select date out of range", + }); + return false; + } + return true; + } + return false; + }; + const isSelectedMonth = (month: number) => month === datePickerHeaderDate.getMonth(); @@ -261,7 +277,7 @@ const DateInputV2: React.FC = ({ onChange={(e) => { setDisplayValue(e.target.value.replaceAll("/", "")); const value = dayjs(e.target.value, "DD/MM/YYYY", true); - if (value.isValid()) { + if (isDateWithinLimits(value)) { onChange(value.toDate()); close(); setIsOpen?.(false);