使用带有onDateClick或onSelect的this.is_selectable(),Javascript NoGray日历无法使用阻止日期

时间:2014-07-30 20:29:36

标签: javascript jquery validation date calendar

我使用带有this.is_selectable()的onDateClick选项遇到了NoGray日历的问题。日历可在http://www.nogray.com/calendar.php找到。我遇到的问题是,最初,当我在已经选择的日历中重新选择日期时,它取消选中它,但使用此修复了:

            onDateClick: function(dt)
            {
                this.select_date(dt);
            }

我从Javascript Calendar deselecting date when date is selected again instead of reselecting it发布的答案得到了此修复,除非现在,如果日期已被阻止,它不会在日历中选择它,但从技术上来说它确实选择了它,因为它仍然显示在以下脚本中,如果日期可选且未被阻止,则仅表示通过。

我的代码如下:

<select id="date1"></select>
<select id="month1"></select>
<select id="year1"></select>

<select id="date2"></select>
<select id="month2"></select>
<select id="year2"></select>


<script src="PATH/TO/ng_all.js" type="text/javascript"></script>
<script src="PATH/TO/components/calendar.js" type="text/javascript"></script>
<script type="text/javascript">
var my_cal1, my_cal2;
ng.ready(function(){
    my_cal1 = new ng.Calendar({
        input: {date:'date1', month:'month1', year:'year1'},
                        selected_date:new Date(),display_date:new Date(),
                        dates_off:[{date:21, month:7, year:2014}],
        events:
        {
            onDateClick: function(dt)
            {
                if (this.is_selectable(dt)){
                    this.select_date(dt);
                    var dt2 = my_cal2.get_selected_date();
                    if ((ng.defined(dt2)) && (dt2 != ""))
                    {
                        theoutputtext=dt2.get_day_since(dt);
                    }
                }
            }
        }
    });

    my_cal2 = new ng.Calendar({
        input: {date:'date2', month:'month2', year:'year2'},
                    dates_off:[{date:21, month:7, year:2014}],
        events:
        {
            onDateClick: function(dt)
            {
                if (this.is_selectable(dt)){
                    this.select_date(dt);
                    var dt1 = my_cal1.get_selected_date();
                    if ((ng.defined(dt1)) && (dt1 != ""))
                    {
                        theoutputtext=dt.get_day_since(dt1);
                    }
                }
            }
        }
    });
});
</script>

“this.is_selectable()”if语句有问题,因为无论日期是否被阻止,它都会将其传递为true。

我尝试使用“onSelect”,使用“onDateClick”并单独使用,但这似乎仍无效。

如何修复此问题,以便在日期被阻止时,它不会将日期传递到日历和“theoutputtext”,并且如果用户选择已经选择的日期,则仍然有效如果没有“this.select_date(dt)”部分,它不会取消选择吗?

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

is_selectable方法返回一个数组,第一个索引为true或false,第二个是原因。您可以在此处找到文档http://www.nogray.com/api/calendar/is_selectable.php

在您的代码中,您可以将if (this.is_selectable(dt)){更改为if (this.is_selectable(dt)[0]){