0
我想在我的項目中使用react-datepicker,我把它封裝起來,所以我可以很容易地將它與redux一起使用,但openToDate
prop似乎沒有做任何事情。是否有其他人遇到過這種情況和/或是否找到了解決方法/解決方法。React-datepicker openToDate不起作用
這裏是我的控制
export function renderDatePicker ({input, placeholder, defaultValue, meta: {touched, error}, ...custom }){
return (
<div className="form-group">
<DatePicker
{...input}
{...custom}
dateFormat="MMDDYYYY"
selected={input.value ? input.value : null}
placeholderText={placeholder ? placeholder : ''}
isClearable={!custom.disabled}
className="form-control" />
{touched && error && <span className="error">{error}</span>}
</div>
);
}
和我如何使用它...
<Field name="StartdDate"
component={renderDatePicker}
openToDate={this.props.minDate}
minDate={this.props.minDate}
maxDate={this.props.maxDate}
placeholder="Select Start Date"
showMonthDropdown
showYearDropdown />
我大部分的使用情況限制可選日期往年,並限制到只有一年(即1990年1月1日 - 1990年12月31日)。因此,總是打開當前日期是一種煩人的,這就是爲什麼我想openToDate
打開到允許的最低日期。出於某種原因,儘管它總是打開到當前日期。
我將它打開到最短日期的唯一方法是將selected
設置爲默認爲defaultValue
並將this.props.minDate
作爲默認值傳遞。但我不希望日期被預選。