From d86bb9317a9596d2b735e92d57d5daf5e89435a7 Mon Sep 17 00:00:00 2001 From: cerbugabriel Date: Wed, 2 Nov 2022 16:47:50 +0200 Subject: [PATCH 1/3] Fix #3559: Component: Calendar -> keepInvalid no longer works --- components/lib/calendar/Calendar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/lib/calendar/Calendar.js b/components/lib/calendar/Calendar.js index 00e2a354ac..3ee6e821ce 100644 --- a/components/lib/calendar/Calendar.js +++ b/components/lib/calendar/Calendar.js @@ -118,7 +118,7 @@ export const Calendar = React.memo( } } catch (err) { //invalid date - const value = props.keepInvalid ? rawValue : null; + const value = props.keepInvalid ? event.value : null; updateModel(event, value); } From a1a1e5d40d8f748a643f2f5d575457ef0aea4baa Mon Sep 17 00:00:00 2001 From: cerbugabriel Date: Wed, 2 Nov 2022 18:22:02 +0200 Subject: [PATCH 2/3] Calendar update fix for isInvalid --- components/lib/calendar/Calendar.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/lib/calendar/Calendar.js b/components/lib/calendar/Calendar.js index 3ee6e821ce..81fd97370c 100644 --- a/components/lib/calendar/Calendar.js +++ b/components/lib/calendar/Calendar.js @@ -118,7 +118,7 @@ export const Calendar = React.memo( } } catch (err) { //invalid date - const value = props.keepInvalid ? event.value : null; + const value = props.keepInvalid ? rawValue : null; updateModel(event, value); } @@ -1961,7 +1961,7 @@ export const Calendar = React.memo( let formattedValue = ''; - if (value) { + if (value instanceof Date) { try { if (isSingleSelection()) { formattedValue = isValidDate(value) ? formatDateTime(value) : ''; @@ -1991,6 +1991,8 @@ export const Calendar = React.memo( } catch (err) { formattedValue = value; } + } else if (props.keepInvalid) { + formattedValue = value; } inputRef.current.value = formattedValue; @@ -2511,7 +2513,7 @@ export const Calendar = React.memo( } } - if (viewDate) { + if (viewDate instanceof Date) { validateDate(viewDate); setViewDateState(viewDate); setCurrentMonth(viewDate.getMonth()); From 2a222ce056f3c07412bdeb37373dc4ebc2bbe425 Mon Sep 17 00:00:00 2001 From: cerbugabriel Date: Wed, 2 Nov 2022 18:40:49 +0200 Subject: [PATCH 3/3] make isSingleSelection support for keepInvalid --- components/lib/calendar/Calendar.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/lib/calendar/Calendar.js b/components/lib/calendar/Calendar.js index 81fd97370c..18a0e82715 100644 --- a/components/lib/calendar/Calendar.js +++ b/components/lib/calendar/Calendar.js @@ -1961,10 +1961,10 @@ export const Calendar = React.memo( let formattedValue = ''; - if (value instanceof Date) { + if (value) { try { if (isSingleSelection()) { - formattedValue = isValidDate(value) ? formatDateTime(value) : ''; + formattedValue = isValidDate(value) ? formatDateTime(value) : props.keepInvalid ? value : ''; } else if (isMultipleSelection()) { for (let i = 0; i < value.length; i++) { let selectedValue = value[i]; @@ -1991,8 +1991,6 @@ export const Calendar = React.memo( } catch (err) { formattedValue = value; } - } else if (props.keepInvalid) { - formattedValue = value; } inputRef.current.value = formattedValue;