how to set one month of date range in fullcalender plugin in jquery

33 Views Asked by At

I am using fullcalender plugin to show calendar and choose a date from. But now I want to show calendar just for a month based on previous dare selected by user but not able to do that.

example: user select a date previously as 27 Apr 2023, so next time when user will see the calendar, it will only show a date range between 28 May - 27 June and then next 28 June - 27 July.

This is my code

var calendar =  $('#calendar').fullCalendar({
    header: {
        left: 'title',
        right: 'prev,next'
    },
    viewDisplay   : function(view) {
        var now = new Date(); 
        var end = new Date();
        end.setMonth(now.getMonth() + 1); //Adjust as needed
        console.log(view.start.getDate());
        var cal_date_string = view.start.getMonth()+'/'+view.start.getFullYear();
        console.log("cal_date_string: "+cal_date_string);
        
        var cur_date_string = now.getMonth()+'/'+now.getFullYear();
        console.log("cur_date_string: "+cur_date_string);
        
        var end_date_string = end.getMonth()+'/'+end.getFullYear();
        console.log("end_date_string: "+end_date_string);

        if(cal_date_string == cur_date_string) { jQuery('.fc-button-prev').addClass("fc-state-disabled"); }
        else { jQuery('.fc-button-prev').removeClass("fc-state-disabled"); }

        if(end_date_string == cal_date_string) { jQuery('.fc-button-next').addClass("fc-state-disabled"); }
        else { jQuery('.fc-button-next').removeClass("fc-state-disabled"); }
     },
    dayClick: function(date,jsEvent,view){
        //code to next
    }
 });

This my code is blocking the month for a month but this doesn't start the date from one month after the previously selected date.

0

There are 0 best solutions below