Re: Not selectable dates
2004/10/01 11:49
Viewed 68857 times
Replies: 5/13

Yes, this is possible.

You have to provide a function that takes a date and returns that day's status, so that the calendar knows wether to disable it or not.  Here's some sample code:

function dateStatus(date) {
var min = new Date(2004,09,30);
var max = new Date(2004,10,05);
if (date.getTime() < min.getTime() ||
date.getTime() > max.getTime())
return true; // true says "disable"
else
return false; // leave other dates enabled
}

Then you need to include this function at Calendar.setup(), like this:

Calendar.setup({
...
dateStatusFunc : dateStatus
...
});

The calendar will call this function for each date in a month and, depending on the result, it will take an action on that date: if your function returns true then the date will be disabled, if it returns false then nothing happens and if it returns a string then that string will be appended to the date's CSS class, thus allowing you to have some “special

Re[2]: Not selectable dates
2004/10/01 12:55
Viewed 75203 times
Replies: 0/0

It sure did !! THNX a lot !

last
Re[2]: Not selectable dates
2004/10/10 13:54
Viewed 74751 times
Replies: 2/4

This way we have the days blocked for selection but the user can still browse thru all the remaining months. It would be very nice it (for the same example: a camping site) if the not valid months would also be invisible. I could limit the year within the code, I would like to limit the months in an equal way. Somebody has a patch already?

last
Re[3]: Not selectable dates
2004/10/10 14:02
Viewed 79938 times
Replies: 1/2

You are right; and many asked for this. A patch wouldn't be impossible, but it would slow down the calendar generation for any month, which surely isn't desirable. :-(

I'll will try to find a way though, but for now you can't do that.

last
Re[3]: Not selectable dates
2006/12/04 20:56
Viewed 43026 times
Replies: 0/0

It looks that user is not only able to browse within disabled days and months, but also selcet those days..

Example:
If I will change month / year to let’s say next one, it will automatically display in select box first available date in that month in my input box, even if I didn’t selected that date. It causes a problem, especially if you will disable some days – it will allow to user select those disabled days using this “hack’. Is there any way how to change this behaviour?

Thanks for help!

last
Re[2]: Not selectable dates
2005/06/21 22:12
Viewed 64717 times
Replies: 1/3

Yeah that prety much works once I got a grip on what it was doing....

last
Re[3]: Not selectable dates
2006/04/20 16:42
Viewed 54335 times
Replies: 1/2

Hi! I used a similar function to leave only an open window or range of dates... but now I have a strange behavior...
The first time I call the calendar if I have some days disabled, when I click in the ones I want it doesn't happen anything (no javascript errors either) until I change month or something like that, but not onclik... if I put an alert on the first line of the the selected function nothing happens so it's not beeing called....

Where is the code which calls the selected??

Thanks!

last
Re[2]: Not selectable dates
2007/04/03 21:35
Viewed 32503 times
Replies: 1/1

When I impliment your code suggestion, my variation shown below, I get some strange behavior:

Calendar.setup({
inputField : "matched_level1",
ifFormat : "%m/%d/%Y",
button : "f_trigger_a",
align : "Tr",
singleClick : true,
dateStatusFunc : dateStatus1
});
function dateStatus1(date) {
var min = new Date(2007,04,03); // Today's date...
var max = new Date(2008,04,03); // Year in the future...
if (date.getTime() < min.getTime() || date.getTime() > max.getTime()) {
return true; // true says "disable"
} else {
return false; // leave other dates enabled
}
}

The calendar displays fine but instead of dates between today (04/03/2007 in my example) and a year from now (04/03/2008) being selectable, the calendar only allows dates 1 month from now (05/03/2007) to a year + 1 month from now (05/03/2008).

Any idea why?

  • b
last
Re[3]: Not selectable dates
2008/02/13 02:46
Viewed 14664 times
Replies: 0/0
Remember that when constructing a new Date() object, the month parameter is the INDEX of the month: 0 = January, 1 = February.... If you're trying to set the date "April 3, 2007", you need to construct it as: new Date(2007,3,3). Or pass it as a formal string: new Date("April 3, 2007");
last
Re[2]: Not selectable dates
2008/05/05 19:27
Viewed 8838 times
Replies: 0/0

Hello,

I have a form with two inputfields for a period. The First one is the from an the secend one is a to date. If the from date is chosen via the calendar I want the to calendar to disable every date < the from date.

My code for this looks like this:

                    <div id="content_input_epoch_start_lable" class="text">Von:</div>
<div id="content_input_epoch_start_input">
<input type="text" style="width:70px;height:13px;" name="f_date" class="solid" id="f_date" readonly="true" />&nbsp;
<img id="f_trigger" style="vertical-align: -35%" src="http://travelload.de/partner/my-travelload.de/messagecenter/gfx/cal.gif">
</div>
<div id="content_input_epoch_stop_lable" class="text">bis:</div>
<div id="content_input_epoch_stop_input">
<input type="text" style="width:70px;height:13px;" name="t_date" class="solid" id="t_date" readonly="true" />&nbsp;
<img id="t_trigger" style="vertical-align: -35%" src="http://travelload.de/partner/my-travelload.de/messagecenter/gfx/cal.gif">
</div>
<script type="text/javascript">


Calendar.setup({
inputField : "f_date", // id of the input field
ifFormat : "%d.%m.%Y", // format of the input field
showsTime : false, // will not display a time selector
button : "f_trigger", // trigger for the calendar (button ID)
singleClick : true, // single-click mode
step : 1 // show all years in drop-down boxes (instead of every other year as default)
});
Calendar.setup({
inputField : "t_date", // id of the input field
ifFormat : "%d.%m.%Y", // format of the input field
showsTime : false, // will not display a time selector
button : "t_trigger", // trigger for the calendar (button ID)
singleClick : true, // single-click mode
step : 1, // show all years in drop-down boxes (instead of every other year as default)
dateStatusFunc : dateStatus
});

function dateStatus(date) {
var minDateString = document.getElementById("f_date").value;
var dateParts = minDateString.split(".");
var min = new Date(dateParts[2], dateParts[1] -1, dateParts[0]);
if (date.getTime() < min.getTime())
return true; // true says "disable"
else
return false; // leave other dates enabled
}
</script>

The disabling works fine, but if a from date is chosen the to calendar will not close after I clicked a date an does not fill a date to the Inputfield, unless I change the month or year (when I step back afterwards it works also fine).

Thx for help

last
Google