React-dates: SingleDatePicker: No way to distinguish between invalid date and empty input

Created on 14 Feb 2018  路  16Comments  路  Source: airbnb/react-dates

SingleDatePicker's onDateChange handler is fired with null when user's input doesn't validate to a date. This can happen when the date is, in fact, invalid 13/13/2018 or when user input is empty.

Is there a way to tell these scenarios apart?

Most helpful comment

We probably should make onDateChange fired with either a Date object or a string (contains whatever user's original input) to fix this issue

All 16 comments

+1

@viktoriyavulfson Did you ever find a solution to this issue?

This is also tripping me up a little. My scenario is that I want to send a request to the server if the user "clears" the input, but I have no way of knowing if the null date arg was because of an actual clearing of the input or a temporary edit that put the input into an invalid state.

Perhaps additional arguments could be passed to the change handler, in addition to the date value? Something that refers to the validity of the current state of the input?

+1

+1 this is driving me insane:)

Its probably a bug though, as onDateChanged should not be triggered at all.
See README:

The SingleDatePicker also manages internal state for partial dates entered by typing (although onDateChange will not trigger until a date has been entered completely in that case).

+1

+1

I fixed this using this strategy:

  • onDateChange callback does not change state of wrapping component if it recieves null as an argument.
  • Put a "clear" button next to the datepicker that sets the state to null.

Not pretty but works....

I would also consider contributing a bugfix, but not sure where to start - i dont really have any experience in contribution to foss - i would love to get some though.

+1 Same problem here

Looks like my +1 comment was marked as spam for some reason, but I am also experiencing the same problem.

All +1 comments are spam; github etiquette is to use an emoji reaction on the OP.

We probably should make onDateChange fired with either a Date object or a string (contains whatever user's original input) to fix this issue

Hi all, huge issue for us. As we don't know if the date is being edited but invalid or just empy. Maybe use null / undefined.

Made a small change to passing the invalid date string back to onChange event.

RE: https://github.com/airbnb/react-dates/pull/2015~~

Looks like there is an open PR here https://github.com/airbnb/react-dates/pull/1941

Any updates on this? Hoping to find a solution on this as well...

really late i guess but i need this too

Hi I checked the actual value of the input. I am not quite sure if I used document.getElementById or a ref to get the input

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Daniel15 picture Daniel15  路  3Comments

HartiganHM picture HartiganHM  路  3Comments

AsasinCree picture AsasinCree  路  3Comments

jpollard-cs picture jpollard-cs  路  3Comments

cemremengu picture cemremengu  路  3Comments