React-day-picker: onDayChange not always called from DayPickerInput

Created on 24 Jan 2018  路  3Comments  路  Source: gpbl/react-day-picker

The onDayChange function is not called where you manually enter invalid text into the text box of the DayPickerInput.

See https://codesandbox.io/s/v6m53q7o47

Select a date - alert is shown

Enter X as the date picker text - no alert

Most helpful comment

I was missing something, input props that you can pass:

inputProps={{ onChange: this.handleInputChange, onBlur: this.handleInputBlur }}

All 3 comments

In daypickerinput.js it has

      if (onDayChange) {
        onDayChange(undefined, {});
      }
      return;
    }
    const day = parseDate(value, format, dayPickerProps.locale);
    if (!day) {
      this.setState({ value });
      return;
    }
    this.updateState(day, value);

perhaps the if(!day) { ... } statement should also call onDayChangedpassing in undefined.

onDayChange only runs if a day is selected from the calendar, but I have the same issue with firing an event from the input. The standard onBlur or onChange events don't run when input text is manually entered. Am I missing something here? I need to be able to validate the input from this field if a user ignores a selection on the calendar but enters invalid text in the input.

I was missing something, input props that you can pass:

inputProps={{ onChange: this.handleInputChange, onBlur: this.handleInputBlur }}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

laidinidis picture laidinidis  路  6Comments

matfork-belatrix picture matfork-belatrix  路  5Comments

magnusohlin picture magnusohlin  路  4Comments

dreamyguy picture dreamyguy  路  5Comments

samsch picture samsch  路  6Comments