Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disabling dates in Dynarch Calendar

Status
Not open for further replies.

stillhanginon

Programmer
Mar 25, 2005
27
US
Hi, I'm using the DHTML Calendar, version 1.0 and need to disable certain dates from being selected.
The documentation says, "You can disable individual dates by supplying a callback function which receives a JS date object and returns true if that date must be disabled, or false otherwise. You can write anything you want in the disabled() handler—just try to make it fast enough, as it will be called many times within milliseconds when the calendar is displayed. Here's an example, suppose you have in your database a list of dates that should be disabled, just convert them to numeric value and build up a hash table, then your disabled() handler can very conveniently return true for them:

Code:
var DISABLED_DATES = {
    20090502: true,
    20090505: true,
    20090510: true,
    20090511: true
};
Calendar.setup({
    cont     : "sample3",
    disabled : function(date) {
        date = Calendar.dateToInt(date);
        return date in DISABLED_DATES;
    }
});

I'm not sure where I would add this code. The files I have are calendar.js and calendar_function.js
I've tried adding it to the calendar_function.js file, but then the calendar just doesn't work. Is there a specific place the code has to be added? I know I'm missing something here and I hope someone can help me.
Please let me know if you need more info.
Thanks,
Jim
 
ensure you are including calendar-setup.js. load it after the other calendar files.

ensure your calendar.setup() function call is AFTER the form with the calendar controls in it, or otherwise conditioned inside a DOMready or onLoad block.

it does not look to me as if you are passing the correct options in the setup function however. but it is a long time since i looked at that particular widget.

i'd guess it should look more like this

Code:
var dateStatusHandler = function(dt, y, m, d){
   return (DISABLED_DATES[y+m+d] === true);
}
calendar.setDateStatusHandler(dateStatusHandler);
calendar.setup({
    inputField  : "sample3"
});
 
Thanks for your response. I'll give your code a try. Should the code go in the calendar_function.js file and where in the file should I place the code?
Thanks,
Jim
 
jpadie said:
ensure your calendar.setup() function call is AFTER the form with the calendar controls in it, or otherwise conditioned inside a DOMready or onLoad block.
 
For anyone following this thread, here is the code I used in the calendar_function.js file to disable dates:

Code:
var DISABLED_DATES = {
    20150313: true,
    20150314: true,
    20150315: true,
	20150316: true,
	20150317: true,
	20150318: true,
	20150319: true
};

function disallowDate(date) {
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var day = date.getDate(); 
  var calendarDate = year*10000 + month*100 + day;
  return calendarDate in DISABLED_DATES; 
}

Jim
 
you don't need that

Code:
function disallowDate(date, y,m,d){
 return (y + (m+1) + d) in DISABLED_DATES;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top