-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #3559: Component: Calendar -> keepInvalid no longer works #3561
Conversation
components/lib/calendar/Calendar.js
Outdated
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think the line need to be this...
const value = props.keepInvalid ? null : rawValue;
if you try your with keepInvalid
it works but if you remove keepInvalid
its allowing invalid characters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference between keepInvalid true and false should only be on onBlur.
You can input invalid characters with it true and false, but, when onBlur state value remains on keepInvalid = true, and on keepInvalid = false makes the state value null. (please test the old version too (8.7.1)
I'm trying to upgrade from 6.6 and it worked as i said, now is broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description of keepInvalid from docs:
keepInvalid | boolean | false | Keep invalid value when input blur. |
---|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just try your fix above with both keepInvalid={true}
and keepInvalid={false}
you will see your fix does NOT work. Then try mine you will see it does work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a couple of digging and found out why it didn't update. updateInputField didn't work properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change of:
formattedValue = isValidDate(value) ? formatDateTime(value) : '';
To
formattedValue = isValidDate(value) ? formatDateTime(value) : props.keepInvalid ? 'value' : ''
Is also a possibility
components/lib/calendar/Calendar.js
Outdated
@@ -1961,7 +1961,7 @@ export const Calendar = React.memo( | |||
|
|||
let formattedValue = ''; | |||
|
|||
if (value) { | |||
if (value instanceof Date) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you can do this here because issingleSelection
its a date but isRangeSelection
and isMultipleSelection
the value is not a DATE its an array of dates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move condition for keepInvalid inside isSingleSelection.
(should only work for isSingleSelection)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move props.keepInvalid to isSingleSelection
Nice job! |
Defect fix for #3559.