stephy / CalendarPicker

CalendarPicker Component for React Native
803 stars 373 forks source link

disable all dates prior to the current date #227

Closed geraldo-thorpe-innovation closed 4 years ago

geraldo-thorpe-innovation commented 4 years ago

Is there any way to disable previous dates, compared to my current date? At the moment, I cannot allow my user to select dates from the past.

geraldo-thorpe-innovation commented 4 years ago

This code resolve my problem:

in this part, we take all the dates prior to the current day, and we add there is a state:

let date = new Date()
const test = date.setDate(new Date().getDate() - 1)

 setPriorDates(test)
<CalendarPicker
   ...
   disabledDates={[priorDates]}
peacechen commented 4 years ago

disabledDates also accepts a function. You could use it like this to disable dates before today:

const today = moment();

<CalendarPicker
   disabledDates={date => date.isBefore(today, "day")}
   //...
/>