calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Thu Feb 17, 2005 3:07 am Post subject: How to set the calendar range dynamically? |
|
|
For FlatCalendarXP, we just need to call the internal function fInitRange(range). e.g.
Code: | <script>
function modRange() {
var beginDate=[2000,10,11];
var endDate=[2020,2,21];
if(self.gfFlat)gfFlat.fInitRange([beginDate,endDate]);
}
</script>
<input type="button" value="modify range" onclick="modRange()"> |
gfFlat is the context name defined in the name&id of your calendar iframe tag, and the range is an array with multiple elements (each element is an date array, e.g. [y,m,d]):- indicates start of range;
- indicates end of range;
- indicates the default month to show if the init month falls out of the range;
- starting from the 4th element, each one indicates a date to be excluded (disabled) in the range.
e.g. the following will exclude Jan 3, 2002 and April 1, 2003 from the range started from Oct 11, 2000 and ended on Oct 11, 2004, with the fallback month set to Oct 2001.
Code: | gfFlat.fInitRange([[2000,10,11],[2004,10,11],[2001,10],[2002,1,3],[2003,4,1]]); |
Note: any of these 4 elements can be set to null if not needed, however, the most important is the 3rd one - because without it the calendar may complain with an alert if the init month of the calendar falls out of range.
For PopCalendarXP, you may also pass the same range object as the 2nd parameter of the fPopCalendar() call. Following is an example, more details can be found in the HelloWorld tutorial.
Code: | gfPop.fPopCalendar(document.myform.mydate,[[1997,1,1],[2020,12,25],[2003,9]]) |
A good example in reality is that some people used the date range demo and wanted to limit the begin date to the existing value in another input box - it's just as easy as going into the plugins.js file, find the the definition of fStartPop() and modify it to be the following:
Code: | function fStartPop(startc,endc) {
_startc=startc;
_endc=endc;
var sd=fParseInput(endc.value);
if (!sd) sd=gEnd;
var beginDate=fParseInput(gContainer.document.getElementById("id_of_the_input_tag").value);
if (!beginDate) beginDate=gBegin;
fPopCalendar(startc, [beginDate,sd,beginDate]);
} |
Last but not least, you can override the fValidRange() in plugins.js and get full control of which days should be disabled. e.g. By appending the following code to agenda.js (not the plugins.js), it will ignore the setting of gBegin, gEnd and fInitRange(), and make all dates unavailable:
Code: | function fValidRange(y,m,d) {
return false; // return false will disable date; true will enable date.
} |
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved. |
|