» Forums
» The DHTML Calendar
» General discussion
» Problem with calendar and dateStatusFunc
Problem with calendar and dateStatusFunc
2006/03/16 18:29
Viewed 8524 times
Replies: 2/6

I'm working on a page that has multiple table rows which contain 2 instances of the Calendar each. Both instances use dateStatusFunc and local functions to specify whether the date is enabled or not and sets the style of the dates that are (valid starting and ending dates for a date range).

It works fine for the most part, except when you click on the enabled date, nothing happens. However, if you click on the Day header, which switches that day of the week to be the "first day" of the week (i.e. the calendar displays Sun-Sat by default, click on Friday and the calendar displays Fri-Thu), the enabled days start working.

Has anyone run into this problem?

*************************************************

<script language="javascript">
Calendar.setup({
    button: 'StartDS_1',
    inputField: 'StartTXT_1',
    ifFormat: '%m/%d/%Y',
    align: 'Bl',
    dateStatusFunc: function(date, y, m, d) { return ValidStart(y,m,d); },
    singleClick: true,
    electric: true
});
</script>

<script language="javascript">
Calendar.setup({
    button: 'EndDS_1',
    inputField: 'EndTXT_1',
    ifFormat: '%m/%d/%Y',
    align: 'Bl',
    dateStatusFunc: function(date, y, m, d) { return ValidStart(y,m,d); },
    singleClick: true,
    electric: true
});
</script>


/* Checks for Saturdays after 10 days from the current date */
function ValidStart(year,month,day)
{
    var chkDate = new Date(year,month,day);
    var curDate = new Date();
    var nextDate = new Date(curDate.valueOf() + 10*24*60*60*1000);
   
    if(chkDate.getDay() == 6)
    {
        if(chkDate > nextDate)
            return "zzz";
    }
    return true;
}


/* Checks for Fridays after 10 days from the current date */
function ValidEnd(year,month,day)
{
    var chkDate = new Date(year,month,day);

    var curDate = new Date();
    var nextDate = new Date(curDate.valueOf() + 10*24*60*60*1000);
   
    if(chkDate.getDay() == 5)
    {
        if(chkDate > nextDate)
            return "zzz";
    }
    return true;
}



Re: Problem with calendar and dateStatusFunc
2006/03/20 18:05
Viewed 10032 times
Replies: 0/0

I've been able reproduce the issue by doing the following:

  1. Click on the calendar icon which displays the calendar (problem: enabled days are not clickable)
  2. Click on a day of week header (normal functionality: this shifts the calendar's first day of week to the day clicked on)
  3. Click on one of the enabled days (outcome: it now works and populates the value field and hides the calendar)

From here on, that specific instanace of the date selector works regardless if I've clicked on the day of week header.

Still looking.....

last
Problem with calendar and dateStatusFunc
2006/04/19 23:38
Viewed 9725 times
Replies: 1/4
by robd

I'm having a problem with dateStatusFunc - I want to disable dates in the past and so my function is simply:
var today = new Date();
return date.getTime() < today.getTime();

This correctly disables all dates before today but prevents me from selecting any date, even the non-disabled ones. Strangely if I reverse the less than comparison to a greater than (return date.getTime() > today.getTime()) then all the dates in the future are disabled but I can at least select dates in the past.

Might anyone tell me why this code, which seems so straightforward, has this strange side effect that you can't select even non-disabled dates?

Regards, Rob

last
Re: Problem with calendar and dateStatusFunc
2006/05/01 19:30
Viewed 11201 times
Replies: 1/3

I was finally able to create a hack around my problem, I added to the Calendar.cellClick in calendar.js the following snippet:

...
(line 578)
Calendar.cellClick = function(el, ev) {

...
(line 592)
cal.date.setDateOnly(el.caldate);
date = cal.date;
if (date) {
Calendar.removeClass(cal.currentDateEl, "selected");
Calendar.addClass(el, "selected");
closing = (cal.currentDateEl == el);

if (!closing) {
cal.currentDateEl = el;
}
}

last
Google