Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disable future dates in material-ui datepicker in reactjs

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?

like image 998
Naveed Aheer Avatar asked Apr 20 '17 10:04

Naveed Aheer


People also ask

How do I turn off future date in Reactjs?

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.

How do you clear the UI Datepicker?

You can set the value property as null and it will clear it.

How do I turn off date picker in react native?

By default, the DatePicker is enabled. To disable the component, set its disabled property to true .


2 Answers

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.

like image 67
Mayank Shukla Avatar answered Oct 04 '22 21:10

Mayank Shukla


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}
/>

like image 28
Ezrqn Kemboi Avatar answered Oct 04 '22 21:10

Ezrqn Kemboi