React Datepicker include days in the future without weekends

Viewed 1014

I'm using React Datepicker found here: https://reactdatepicker.com/#example-11

What I'm trying to do is only allow the user to select a day UP TO 3 "business" days in advance. Using filterDate I was able to filter calendar to only display weekdays. I see in the documentation they have a includeDates prop to allow user to only select certain dates. I'm trying to figure out how to only include up to 3 business days. So if today is Friday. The user will only be able to select: Friday, Monday, Tuesday for that week.

Here is my code:

        this.state = {
            dateFrom: new Date(),
        }

render() {

    const isWeekday = date => {
        const day = getDay(date);
        return day !== 0 && day !== 6;
    };      


    return (
        <div>
        
            <DatePicker
                selected={this.state.dateFrom}
                filterDate={isWeekday}
                //includeDates={[new Date(), addDays(new Date(), 1)]}
                onChange={date=>this.setState({dateFrom: date })}
                className="form-control"
            />


        </div>
    )
}
0 Answers
Related