Amazon Ad

Thursday, 4 July 2013

Disable Dates In Tigra Calendar After Current Date

Hi,

I was working in Tigra Calendar which is a really good javascript calendar library. I was stucked when there was a need to disable dates after the current date. Here is how i was able to solve the problem.

Step 1: Edit tcal.css and add the following lines

div#tcal td.disabled_days {
font-style: italic;
color: silver;
cursor: auto;
}

Step 2: Edit tcal.js and go to the function f_tcalGetHTML (d_date)

After the lines :
if (d_current.getMonth() != d_date.getMonth())
                a_class[a_class.length] = s_pfx + 'OtherMonth';
           
if (d_current.getDay() == 0 || d_current.getDay() == 6)
            a_class[a_class.length] = s_pfx + 'Weekend';
           
if (d_current.valueOf() == d_today.valueOf())
                a_class[a_class.length] = s_pfx + 'Today';
           
if (d_current.valueOf() == d_selected.valueOf())
                a_class[a_class.length] = s_pfx + 'Selected';

And Before the line
d_current.setDate(++n_date)

Add these lines
//start of ritesh's code
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
if (dd < 10) { dd = '0' + dd } if (mm < 10) { mm = '0' + mm } today = mm + '/' + dd + '/' + yyyy;
today=new Date(today);

var dd1 = d_current.getDate();
var mm1 = d_current.getMonth() + 1; //January is 0!
var yyyy1 = d_current.getFullYear();
if (dd1 < 10) { dd1 = '0' + dd1 } if (mm1 < 10) { mm1 = '0' + mm1 } d_current_1 = mm1 + '/' + dd1 + '/' + yyyy1;
d_current_1=new Date(d_current_1);

//Check if the date of calendar is less than today's date
if (d_current_1 <= today) {
   //default code
    s_html += '<td' + f_tcalRelDate(d_current) + (a_class.length ? ' class="' + a_class.join(' ') + '">' : '>') + n_date + '</td>';
}
else {
    s_html += '<td class="disabled_days">' + n_date + '</td>'
}


And That's It!! Check the calendar the dates after the current dates would be disabled .


Thanks
Ritesh Tandon

7 comments:

Anonymous said...

thank you so much dude its awesome

Ritesh said...

Glad it helped!!

Unknown said...

That's very helpful...thank you very much..!!

Unknown said...

how to disable date 3 days from this day..

Unknown said...

thank you so much!

Ritesh said...

Glad it helped.

Ritesh said...

Thank you

Post a Comment

Comments are welcome, Please join me on my Linked In account

http://in.linkedin.com/pub/ritesh-tandon/21/644/33b

How to implement Captcha v3 in ASP.NET

 I was facing an issue of dom parsing in my website. I finally resolved it by using Google Captcha V3. Step 1: Get your keys from https:...