-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[pickers] DateTime.fromISO() is not handling null values #10192
Comments
What you are describing is the behavior from Luxon. I would advise you to always store a Luxon object in state, not an ISO string. Or if you really need an ISO string, they check if it is null and if so pass null to the picker const parsedValue = React.useMemo(() => value == null ? value : DateTime.fromISO(value), [value]) In which case you need to stringify it back in your change handler to actually store a string. |
@flaviendelangle Thanks for your suggestion. Adding a null check does work. I was just confused with the fact that when we add some month or day and then remove everything, the value becomes null again but this time it doesn't throw the error and reason comes as null instead of invalidDate which is a bit weird. Unfortunately I couldn't find any examples of initializing a datepicker with null or empty values for luxon adapter as well. |
These behaviors are not specific to Luxon. If you are still doing
I did not understand that part, could you please describe more in depth? |
This answers my question. I'm now using the null check for the initialization. Thanks for your help. |
Duplicates
Latest version
Steps to reproduce 🕹
Link to live example: https://codesandbox.io/s/restless-shadow-q37dg4?file=/Demo.tsx
Current behavior 😯
If we initialize the Date Picker with null values, the DateTime.fromISO() method throws an invalidDate error.
Expected behavior 🤔
the DateTime.fromISO() method should be able to handle null values for initializing the component with empty values.
Context 🔦
I'm trying to initialize the date picker component with empty value.
Your environment 🌎
npx @mui/envinfo
Order ID or Support key 💳 (optional)
59954
The text was updated successfully, but these errors were encountered: