根据documentation,将日历的minimumDate
设置为“会将任何较早的日期重置为该日期”,但是我想禁止选择任何先前的日期。该控件为最短日期的月份禁用“上一个”月份按钮,但仍允许选择较早的日期。
最佳答案
经过一番搜索后仍未找到解决方案,我正在发布一个最终想到的解决方案。使用日历的disabled dates rules,我创建了以下内容:
YUI().use('calendar', function (Y) {
var calendar, rules,
settings = { contentBox: '#dueDateSelect', minimumDate: new Date() };
function getDisabledDatesRule(date, name) {
var year = date.getFullYear(),
month = date.getMonth(),
daybefore = date.getDate() - 1,
r = {};
r[year] = {};
r[year][month] = {};
r[year][month]['1-' + daybefore] = name;
return r;
}
if (settings.minimumDate) {
settings.disabledDatesRule = 'days-before-min';
rules = getDisabledDatesRule(
settings.minimumDate,
settings.disabledDatesRule
);
}
calendar = new Y.Calendar(settings).render();
if (rules) {
calendar.set("customRenderer", {
rules: rules
});
}
});