简体   繁体   中英

First and third saturday disable fullcalendar

I want to disable first and third saturday of the month and I'm using fullcalendar library to show all events on my calendar. is it possible to to the same? please advice, answers will be appreciated.

Thanks

Include Date.js in your project. Now use the following code.

$(function() {
    $( "#pickdate" ).datepicker({
        dateFormat: 'dd MM yy',
        beforeShowDay: checkBadDates
        });
      }

So here I'm just setting the date format and using the beforeShowDay event to call a function to check if any of the dates should be disabled:

var fisrtSaturday=Date.today().first().saturday();  
var thirdSaturday=Date.today().third().saturday();      
var $myBadDates = new Array(fisrtSaturday,thirdSaturday);
function checkBadDates(mydate){
var $return=true;
var $returnclass ="available";
$checkdate = $.datepicker.formatDate('dd MM yy', mydate);
for(var i = 0; i < $myBadDates.length; i++)
   {    
       if($myBadDates[i] == $checkdate)
       {
        $return = false;
        $returnclass= "unavailable";
       }
   }
   return [$return,$returnclass];
   }

This code will disable 1st and 3rd saturday

beforeShowDay : function (date) {
                    var dayOfWeek = date.getDay ();
                    var dateOfMonth = date.getDate();   
                    var weekOfMonth = (dateOfMonth/7);
                    if ( (dayOfWeek == 6 && (weekOfMonth <= 1 || (weekOfMonth == 3 || (weekOfMonth < 3 && weekOfMonth > 2))))) return [false];
                    else return [true];
                },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM