-
Notifications
You must be signed in to change notification settings - Fork 105
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
Bug - [DatePicker] - [validator function converts date automatically and exports a new date when users input some special wrong date ] #1269
Comments
Would it be helpful if we passed back the original date provided by the user in addition to the converted valid date as part of the callback function? That wouldn't be a breaking change. It would still display the 'corrected' value in the input. |
This is not exactly an issue imho. To handle the use case defined above, can we use the value which gets passed in onChange(_event, value, date) ? |
hm... it's a interesting request since typing an poorly formatted date does trigger the error state, so the only dates we are talking about are the ones that native JS is converting to the equivalent valid date - and we want to be sure that if there is a properly formatted date in the datepicker input, that it corresponds to a valid date in the datepicker's calendar when its opened. I guess the solution could be that we somehow override JS's native conversion and display the datepicker is invalid with an error message. |
@nicolethoen I was thinking of a similar approach to display the error message when invalid date is entered. |
I think the datetimeUtils.ts is fine, it receives the date object after conversion. |
I'm going to send this issue over to design for them to consider the ideal interaction for when someone tries to input Sept 31 into the date picker. |
@nicolethoen Can we keep the interaction as it is now. Basically, the dateParse returns false in case of any invalid date format, we can introduce one more check here to also check for the actual invalid date, and if so, the dateParse will return false as it does now. Would like me to send a PR for review on patternfly-react ? |
You are welcome to open a PR! That will give us an example to interact with as we evaluate the interaction/experience. |
Describe the problem
PatternFly DatePicker component has converted 2023-06-31 into 2023-07-01 for us, which triggered our weekend validation.
Actually, I want to get the true value 2023-06-31, I know its an invalid date, but it's true, it makes sure our logic depends on the users input value.
How do you reproduce the problem?
I show a sample demo like below:
<DatePicker validators={[rangeValidator]} />
function rangeValidator(date: Date) {
const dayOfWeek = new Date(date).getDay();
const isWeekend = dayOfWeek === 6 || dayOfWeek === 0
console.log("date==", date);// 2023-07-01, 2022-10-01, 2023-05-01
if (isWeekend) {
return "Date falls on weekend.";
}
return "";
}
I have tried other cases like 2022-09-31 => 2022-10-01, 2023-04-31 => 2023-05-01, the DatePicker component converts these dates automatically and exports the later value, resulting in a validation notice.
Expected behavior
I want to get the true value the users input, like 2023-06-31
Is this issue blocking you?
Not yet
Screenshots
If applicable, add screenshots to help explain the issue.
What is your environment?
What is your product and what release date are you targeting?
Any other information?
The text was updated successfully, but these errors were encountered: