haoxins / react-flatpickr

flatpickr for React
MIT License
598 stars 102 forks source link

Set dynamic maxDate through MobX computed value #106

Open tonycaputome opened 5 years ago

tonycaputome commented 5 years ago

Hi guys I am facing a problem, when I try to set a dynamic maxDate with a MobX computed value. I have one picker which onChange event sets a another variable in the store that should be the new maxDate of another picker (it can be a future date)

// this is the store variable, that initially it's equals to now (formatted string)
Store.startDate  =  '2019-09-30T09:18:28'

When the first picker changes sets the Store.startDate with his value.

// flatpikr 1
<Flatpickr
   options={{
   onChange: (selectedDates, dateStr) => {
     // this is MobX action to change the observable value the result will be Store.startDate = dateStr;
      Store.setStartDate(dateStr);
    }
  }}
/>;
// flatpikr 2
<Flatpickr options= {
  "placeholder": "Adesso",
  "options": {
    "enableTime": true,
    "time_24hr": true,
    "maxDate": Store.startDate ,
     "disableMobile": true,
  }
} />

When I change the first time the variable from the first picker, the months Dropdown is broken and shows only one month, the current month.

If is set a static string like this 2019-09-30T09:18:28, the months Dropdown works fine.

Thank you !