React-dates: Minimum and Max Dates on Single Date Picker

Created on 1 Nov 2016  路  7Comments  路  Source: airbnb/react-dates

Question,

Is there a way to pass a min/max date value to the single date picker? I'd like the user to only select dates that are obviously not in the past or way in the future...

Nice plugin by the way :)

Thanks!

Andre

Most helpful comment

@andrefox333 just in case you still need it, I've submitted a PR that should solve your problem. Check it out -> #172

All 7 comments

@andrefox333 you can pass an isOutsideRange predicate function as a prop that can return true or false if the date is valid, which would allow you to restrict which dates are selectable.

@ljharb, thanks for your reply :), I'm having a couple issues with the predicate function. If I have two input fields (startDate, endDate), I'd like my endDate input to not be able to select anything past the startDate. Very similar to how the date picker range component works.

How does the isOutsideRange function know that the days from the startDate and before are not selectable?

I figured passing in the startDate into the function and do some checking with it would be enough but it's not working as intended. What should I be passing into the isOutsideRange function?

If you want a start and end date linked like that, why not use the DateRangePicker?

Either way, you can do it with your own wrapper component around two single date pickers, and that wrapper component would know onSelect/onChange what dates had been selected.

@ljharb is right. The SingleDatePicker you're using for your end date needs to use your current start date in the logic for isOutsideRange somehow, which means you need a wrapper for both instances that would know about both the selected startDate and endDate

@andrefox333 just in case you still need it, I've submitted a PR that should solve your problem. Check it out -> #172

@simonemonetti Thank you :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jesus-Gonzalez picture Jesus-Gonzalez  路  3Comments

Daniel15 picture Daniel15  路  3Comments

krissalvador27 picture krissalvador27  路  3Comments

sag1v picture sag1v  路  3Comments

yokomizor picture yokomizor  路  3Comments