INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Disabling dates in Dynarch Calendar

Disabling dates in Dynarch Calendar

(OP)
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

RE: Disabling dates in Dynarch Calendar

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"
}); 

RE: Disabling dates in Dynarch Calendar

(OP)
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

RE: Disabling dates in Dynarch Calendar

Quote (jpadie)


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.

RE: Disabling dates in Dynarch Calendar

(OP)
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

RE: Disabling dates in Dynarch Calendar

you don't need that

CODE

function disallowDate(date, y,m,d){
 return (y + (m+1) + d) in DISABLED_DATES;
} 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close