问题
I am having a problem with the NoGray Calendar using the onDateClick selection with this.is_selectable(). The calendar can be found at http://www.nogray.com/calendar.php. The problem I am having is that originally, when I reselected a date in the calendar that had already been selected, it unselected it, but using this fixed that:
onDateClick: function(dt)
{
this.select_date(dt);
}
I got this fix from the answer to this was posted at Javascript Calendar deselecting date when date is selected again instead of reselecting it, except now, if the date has been blocked, it doesn't select it in the calendar but technically it does select select it as it still shows in the following script which is only meant to pass if the date is selectable and not blocked.
The code I have is as follows:
<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>
There is something wrong with the "this.is_selectable()" if statement as it keeps passing it as true whether the date is blocked or not.
I have tried this with "onSelect", with "onDateClick" and on its own, but that still doesn't seem to work either.
How can this be fixed to work so that when the date is blocked, it doesn't pass the date through to the calendar and the "theoutputtext" as well as still working if a user selects a date that is already selected and does not unselect it as it does without the "this.select_date(dt)" part?
Thanks in advance for your help.
回答1:
the is_selectable method returns an array with the first index is as true or false and the second is the reason. You can find the docs here http://www.nogray.com/api/calendar/is_selectable.php
In your code, you can change the if (this.is_selectable(dt)){ to if (this.is_selectable(dt)[0]){
来源:https://stackoverflow.com/questions/25046337/javascript-nogray-calendar-not-working-with-blocked-dates-using-this-is-selectab