React-day-picker: Checking for empty input

Created on 27 Aug 2018  路  4Comments  路  Source: gpbl/react-day-picker

Hi,

I want to check if the DayPickerInput field is empty. Currently I just receive an undefined for both cases empty and invalid date for the onDayChange method. With this I'm not sure if the date field is really empty or invalid.

Any ideas?

A solution proposal could be:
Add a modifier "invalid-date" if the date is invalid or empty if the date input field is empty. In both cases the value/day would stay undefined.

Thanks a lot for support.

Most helpful comment

Yes this is true. I could add a third argument to onDayChange. I think I could send the DayPickerInput instance so you would have full access to it:

onDayChange(day, modifiers, instance) {
    if (instance.getInput().value === '') {
      this.setState({ inputIsEmpty: true });
    }
}

All 4 comments

Yes this is true. I could add a third argument to onDayChange. I think I could send the DayPickerInput instance so you would have full access to it:

onDayChange(day, modifiers, instance) {
    if (instance.getInput().value === '') {
      this.setState({ inputIsEmpty: true });
    }
}

Your solution with a third parameter sounds better 馃憤

@olimination please upgrade to v7.2.1! Check out this example: http://react-day-picker.js.org/examples/input-state

Thanks a lot @gpbl
I have integrated the new version and it seems to work smoothly!

Was this page helpful?
0 / 5 - 0 ratings