Skip to content
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

Merged
merged 3 commits into from
Nov 2, 2022
Merged

Fix #3559: Component: Calendar -> keepInvalid no longer works #3561

merged 3 commits into from
Nov 2, 2022

Conversation

cerbugabriel
Copy link
Contributor

@cerbugabriel cerbugabriel commented Nov 2, 2022

Defect fix for #3559.

@@ -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;
Copy link
Member

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

Copy link
Contributor Author

@cerbugabriel cerbugabriel Nov 2, 2022

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

@cerbugabriel cerbugabriel Nov 2, 2022

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

@@ -1961,7 +1961,7 @@ export const Calendar = React.memo(

let formattedValue = '';

if (value) {
if (value instanceof Date) {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right

Copy link
Contributor Author

@cerbugabriel cerbugabriel left a 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)

Copy link
Contributor Author

@cerbugabriel cerbugabriel left a 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

@melloware
Copy link
Member

Nice job!

@melloware melloware merged commit d901b4d into primefaces:master Nov 2, 2022
@melloware melloware linked an issue Nov 2, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calendar : keepInvalid no longer works
2 participants