1

I have a requirement to display start and end-date in material UI. The end-date field must not allow users to select before dates from selected start-date. I am using text field type date material UI, but is not working. please help

<TextField 
    type="date"
    defaultValue={moment().format("yyyy-mm-dd")}  
    onChange={endDate}
    InputProps={{
       min: "2020-01-04",
    }}
/>      
mural
  • 29
  • 1
  • 8
  • Does this answer your question? [limit a select dates in date range picker and disable other days javascript Set maximum date dynamically](https://stackoverflow.com/questions/64255771/limit-a-select-dates-in-date-range-picker-and-disable-other-days-javascript-set) – Randy Casburn Jan 06 '21 at 20:17

2 Answers2

1

Try the following code snippet. It should do the trick.

<TextField
  InputProps={{inputProps: { min: "2020-05-01", max: "2020-05-04"} }}
/>
Zahid Hasan
  • 527
  • 4
  • 11
  • Excellent, thanks for you help. I changed your code, since I am getting date from state variable InputProps={{ inputProps: { min: `${startDate}`, max:""}, }} it worked. thank you – mural Jan 06 '21 at 20:29
0

The onChange prop always accepts a function to invoke when input's content changes. It propagates a html event, eg.

<TextField 
    type="date"
    defaultValue={moment().format("yyyy-mm-dd")}  
    onChange={(e) => console.log(`your input's value is: ${event.target.value}`) }
    InputProps={{
       min: "2020-01-04",
    }}
/>
k-wasilewski
  • 3,943
  • 4
  • 12
  • 29