how to disable future dates in material-ui datepicker in reactjs?
I want to disable future dates that are after today's in material-ui in ReactJS. How can I disable future dates?
To disable the dates, we have to use the isValidDate property of the react-datetime. As per the documentation, isValidDate is the function and by default is returning the true value.
You can set the value property as null and it will clear it.
By default, the DatePicker is enabled. To disable the component, set its disabled property to true .
There is a property maxDate
of DatePicker
, that you can set to today's date, it will not allow to select the future dates.
maxDate = {new Date()}
Use it Like this:
<DatePicker
onChange= {...}
mode="landscape"
value={...}
floatingLabelText="Date"
minDate={...}
maxDate={new Date()} //maxDate
/>
Note: You can specify the minimum date also, in minDate
.
Check the DOC.
With the current material-ui and if you are using KeyboardDatePicker then, the following will work
import { KeyboardDatePicker } from '@material-ui/pickers';
<KeyboardDatePicker
// other props
disableFuture={true}
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With