简体   繁体   English

如何使用日期选择器禁用今天的日期 - 材质 ui

[英]How to Disable today's date using date pickers - material ui

I'm working on a react project where I'm using material-ui-date-pickers and i want to disable today's date since the project is based on manufacturing products, expiration date of products and billing.我正在做一个反应项目,我正在使用material-ui-date-pickers并且我想禁用今天的日期,因为该项目基于制造产品、产品的到期日期和计费。 Since Manufacturing date and expiration date cannot be same,I want to disable today's date for expiration date.由于制造日期和到期日期不能相同,我想禁用今天的到期日期。 I see props minDate, maxDate can be used, but is it possible to disable today's date using the same?我看到道具minDate, maxDate可以使用,但是否可以使用相同的禁用今天的日期? Below is my code.下面是我的代码。

      <MuiPickersUtilsProvider utils={MomentUtils}>
            <KeyboardDatePicker
              autoOk={true}
              variant='inline'
              inputVariant='outlined'
              format={dateFormat}
              fullWidth
              name='expirationDate'
              value={expirationDate}
              onChange={ (date) => handleDate(date)}
              placeholder={dateFormat}
              size='small'
              disableFuture={true}
              views={['date', 'month', 'year']}
            />
          </MuiPickersUtilsProvider>

Yes, this be can done using JavaScript date method and using the props minDate, maxDate .是的,这可以使用 JavaScript 日期方法和使用道具minDate, maxDate

First declare the new date using首先使用声明新日期

const today = new Date();

and in maxDate prop subtract today's date by 1 to get yesterday's date and give it as maxDate .并在maxDate道具中将今天的日期减去 1 以获得昨天的日期并将其作为maxDate

maxDate={today.setDate(today.getDate() - 1)}

So your complete code will be所以你的完整代码将是

<MuiPickersUtilsProvider utils={MomentUtils}>
            <KeyboardDatePicker
              autoOk={true}
              variant='inline'
              inputVariant='outlined'
              format={dateFormat}
              fullWidth
              name='expirationDate'
              value={expirationDate}
              onChange={ (date) => handleChangeDate(date)}
              placeholder={dateFormat}
              size='small'
              disableFuture={true}
              views={['date', 'month', 'year']}
              maxDate={today.setDate(today.getDate() - 1)}
            />
          </MuiPickersUtilsProvider>

Just add diablePast for the element KeyboardDatePicker只需为元素 KeyboardDatePicker 添加 diablePast

 <MuiPickersUtilsProvider utils={MomentUtils}> <KeyboardDatePicker autoOk={true} diablePast variant='inline' inputVariant='outlined' format={dateFormat} fullWidth name='expirationDate' value={expirationDate} onChange={ (date) => handleDate(date)} placeholder={dateFormat} size='small' disableFuture={true} views={['date', 'month', 'year']} /> </MuiPickersUtilsProvider>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Material ui reactjs 从今天开始禁用过去的日期? - How to disable past dates from today date with Material ui reactjs? 如何删除日历@material-ui/pickers 中的默认选定日期? - How to remove default selected date in Calendar @material-ui/pickers? Material-UI:如何将两个日期选择器放在同一行上? - Material-UI: How to put two Date Pickers on same line? 带有日期和时间选择器的样式材质 UI InputBase - Style Material UI InputBase with Date & Time pickers 带有 Formik 的 Material UI 选择器,用于日期和时间组件,带有秒数 - Material UI Pickers with Formik for both Date and Time components with seconds Material Ui - 日期文本字段禁用日期 - Material Ui - Date Textfield disable date 如何在jQuery DatePicker(Wordpress)中禁用今天的日期 - How to disable today's date in jQuery DatePicker (Wordpress) 如何在日历控件中从今天的日期禁用过去的日期? - How to disable past dates from today's date in calendar controle? 如何在每次使用jQuery或javascript后的下午6:30之后禁用datepicker中的今天日期 - How do I disable today's date in datepicker after 6:30pm of every using jQuery or in javascript 如果使用JavaScript选中了复选框,如何插入今天的日期并禁用输入 - How to insert today's date and disable input if checkbox is checked using javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM