Giter Site home page Giter Site logo

Comments (4)

flaviendelangle avatar flaviendelangle commented on September 26, 2024

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.

Arkamit avatar Arkamit commented on September 26, 2024

@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.

flaviendelangle avatar flaviendelangle commented on September 26, 2024

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.

Arkamit avatar Arkamit commented on September 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.