Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RangeCalendar] Custom validation for start/end date input #647

Open
BionBit opened this issue Dec 2, 2019 · 0 comments
Open

[RangeCalendar] Custom validation for start/end date input #647

BionBit opened this issue Dec 2, 2019 · 0 comments

Comments

@BionBit
Copy link

BionBit commented Dec 2, 2019

Issue happens in these cases,

  • start time is higher than end time
  • end time is lower than start time

STR:

  1. Open the RangeCalendar
  2. Input the start date in the input field, 2 Dec
  3. Input the end date in the input field, 1 Dec
  4. Notice that the calendar start selection state resets, which is undesirable - people might just want an error indicator and fix the date themselves

Proposed fix (tested locally),
Allow the option the inject a custom dateInputValid checker, so the date input turns red in the above cases.

Example,
RangeCalendar,

/*
Closure magic used for injecting a validation rule for the dateinput when,
- start time is higher than end time
- end time is lower than start time
The alternative involves spaghetti code and multiple points of state mutation.
*/
<CalendarPart
...
dateInputValid={((endValue) => ((startDate) => startDate.isBefore(endValue)))(selectedValue[1])}
/>
<CalendarPart
...
dateInputValid={((startValue) => ((endDate) => endDate.isAfter(startValue)))(selectedValue[0])}
/>

CalendarPart,

<DateInput
...
isValid={dateInputValid}
/>

DateInput,

onInputChange = (event) => {
      const str = event.target.value;
      - const { disabledDate, format, onChange, selectedValue } = this.props;
      + const { disabledDate, format, onChange, selectedValue, isValid } = this.props;
  
      + if (!isValid(moment(str, format, true))) {
      +   this.setState({
      +     invalid: true,
      +     str,
      +   });
      +   return;
      + }
      ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant