EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: jjosotoro on March 02, 2015, 05:01:06 AM



Title: Disable holidays and weekends on calendar (datebox)
Post by: jjosotoro on March 02, 2015, 05:01:06 AM
hello.

This code uses the validator property of the calendar control of a datebox; to use it only on a calendar just change the line:

Code:
$('#MyDateBox').datebox().datebox('calendar').calendar({

for this:

Code:
$('#MyCalendar').calendar({

To disable especific dates:

Code:
$(function(){
var NoValDates = ["01/01/2015", "12/01/2015", "23/03/2015", "02/04/2015", "03/04/2015", "01/05/2015", "18/05/2015", "08/06/2015", "15/06/2015", "29/06/2015", "20/07/2015", "07/08/2015", "17/08/2015", "12/10/2015", "02/11/2015", "16/11/2015", "08/12/2015", "25/12/2015"];
var x = NoValDates.length;
 $('#MyDateBox').datebox().datebox('calendar').calendar({
   validator: function(date){
    for (j=0;j<x;j++){
     var d = NoValDates[j].slice(0,2);
     var m = NoValDates[j].slice(3,5)-1;
     var y = NoValDates[j].slice(6,10);
       if(date.getDate()==d  && date.getMonth()==m && date.getFullYear()==y){
return false;
       }
    }

    if(date.getDay()==0 || date.getDay()==6){return false;}else{return true;}; //disables weekends
    return true;
   }
  });
});

The date format used in this code is dd/MM/yyyy.

regards.