jay*_*uto 7 javascript datepicker reactjs material-ui redux-form
我正在为 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)}
/>
);
};
Run Code Online (Sandbox Code Playgroud)
如果我想禁用任何一天/秒,我应该在 disabledDate(){...} 中写什么?
Har*_*dia 16
这是需要添加的示例代码。您可以参考此链接了解更多详情 - 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;Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15493 次 |
| 最近记录: |