1

根据文档,设置minimumDate日历将“将任何更早的日期重置为该日期”,但我想禁用任何先前日期的选择。该控件禁用最小日期月份的“上一个”月份按钮,但仍允许选择更早的日期。

4

3 回答 3

2

我以一种更简单的方式完成了它,希望对您有所帮助:

    //Setting the date to today's date.  
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth(); //January is 1
var yyyy = today.getFullYear();


var calendar = new Y.Calendar({
  contentBox: "#mycalendar",
  width:'340px',
  showPrevMonth: true,
  showNextMonth: true,
  minimumDate: new Date(yyyy, mm, dd) , 
  date: new Date()}).render();
于 2013-11-07T19:54:02.450 回答
2

经过一番搜索后没有找到解决方案,我发布了一个我终于想出的解决方案。使用日历的禁用日期规则,我创建了以下内容:

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
        });
    }

});
于 2012-06-01T20:20:58.323 回答
0

I know you've asked about YUI3 Calendar, but only if you need a second option, you'll probably want to test JSCal2 I finally understood how to accomplish this with it: All you need to do it's to use the present day as "min" so today it's the first selectable day! Copy and paste this, it works:

<input size="40" id="cal_txt_date" />
<button id="cal_btn">...</button>
<br />
<script type="text/javascript">//<![CDATA[ 
  var now = new Date();
  var cal = Calendar.setup({ min : now, trigger : "cal_btn", });
  cal.manageFields("cal_btn", "cal_txt_date", "%A %e de %B del %Y a las %I:%M %p");
//]]>
</script>

As you can see a new date object it's created in the variable "now", and it is set to "min" (or max if future dates shouldn't be selected) I hope this helps you =) If you paste my code as it is here, it should work with JSCal2.

于 2012-06-01T20:36:37.103 回答