gpt4 book ai didi

javascript - 在 React 中禁用 Material ui 日历中的特定日期

转载 作者:行者123 更新时间:2023-12-03 06:54:09 24 4
gpt4 key购买 nike

我正在为 React js 使用 material-ui v0.20.0
这是我的 DatePicker 组件

<Field
name='appointmentDate'
label="Select Date"
component={this.renderDatePicker}
/>

renderDatePicker = ({ input, label, meta: { touched, error }, ...custom,props }) => {
return (
<DatePicker
{...input}
{...custom}
autoOk={true}
floatingLabelText={label}
dateForm='MM/DD/YYYY'
shouldDisableDate={this.disabledDate}
minDate={ new Date()}
value={ input.value !== '' ? input.value : null }
onChange={(event, value) => input.onChange(value)}
/>
);
};

如果我想禁用任何一天/秒,我应该在 disabledDate(){...} 中写什么?

最佳答案

这是需要添加的示例代码。
您可以引用此链接了解更多详情 - https://material-ui.com/components/pickers/#date-time-pickers

您可以根据需要添加条件以禁用日期。

import React from 'react';
import DatePicker from 'material-ui/DatePicker';

function disableWeekends(date) {
return date.getDay() === 0 || date.getDay() === 6;
}

function disableRandomDates() {
return Math.random() > 0.7;
}
/**
* `DatePicker` can disable specific dates based on the return value of a callback.
*/
const DatePickerExampleDisableDates = () => (
<div>
<DatePicker hintText="Weekends Disabled" shouldDisableDate={disableWeekends} />
<DatePicker hintText="Random Dates Disabled" shouldDisableDate={disableRandomDates} />
</div>
);

export default DatePickerExampleDisableDates;

关于javascript - 在 React 中禁用 Material ui 日历中的特定日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49491569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com