Comments (4)
What you are describing is the behavior from Luxon.
DateTime.fromISO(value)
returns an invalid date, so when you pass it to the picker, we display an error.
I would advise you to always store a Luxon object in state, not an ISO string.
Because right now, you are storing an ISO string, parsing it with fromISO
and then storing a Luxon object, that will be parsed with DateTime.fromISO
, this works but it's super weird and goes against Luxon types.
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.
from mui-x.
@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.
from mui-x.
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.
For any adapter, null
is the value when no date is selected, whereas the invalid date (in the format of your date library) represents an invalid date.
If you are still doing fromISO
even with the null check, could you tell me why you are not storing the parsed object in state instead of parsing it during the render ?
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.
I did not understand that part, could you please describe more in depth?
When you remove all the sections, the value is null so we fire onChange
with null not with an invalid date.
Our components almost never fires an invalid date, the only reason I can see is if you type something like 31 April
.
from mui-x.
When you remove all the sections, the value is null so we fire onChange with null not with an invalid date.
Our components almost never fires an invalid date, the only reason I can see is if you type something like 31 April.
This answers my question. I'm now using the null check for the initialization. Thanks for your help.
from mui-x.
Related Issues (20)
- [question] data-grid not works on old version browser,but why the offical demo can run on the same browser? HOT 7
- Page Broke in React Bar Chart. HOT 5
- [charts] Allow to partially provide bar/line charts x-axis
- [pickers] Providing unknown props to Picker components don't spread them to the root element HOT 1
- [pickers] DatePicker/TimePicker render at top left corner (with InputBase) HOT 7
- [charts][zoom] Support side scrolling to pan HOT 3
- [pickers] `StaticDatePicker` throws an error when used inside <CssVarsProvider> from Joy UI HOT 4
- [data grid] Printing large data set will crash the browser HOT 3
- [data grid] How to autosize and header filters work well? HOT 4
- [pickers] Change of locale adapter import for moment.js HOT 2
- [pickers] Date Calendar like an actual Outlook-ish calendar HOT 4
- [data grid] Possibility to save changes in data grid, like column sorting, hiding ordering HOT 2
- [pickers] Translating page in Edge make calendar show March when not March HOT 5
- [data grid] tests fail when calling setCellFocus HOT 1
- [docs] Recommended Pickers styling approach shown on all styling approaches HOT 3
- [pickers] MUI DateRangePicker property "name" doesnt render HOT 3
- [charts][RFC] Replace `DefaultXxxx` by the usage of hooks
- [charts] Remove deprecated props HOT 1
- [data grid] Cell stealing focus from modal and onClicks for buttons rendered inside cells fire when the user hits the enter key HOT 3
- Add PDF component HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mui-x.