Search code examples
jqueryfullcalendarappointment

jQuery full calendar generate appointments for complete month


Hi all need a help with jQuery fullcalender.

$("body").on("click", '#schedule-appointments', function(){
    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y =date.getFullYear();
    var newEvent = {
        title: 'NEW EVENT',
        start: '10:00',
        end: '14:00',
        dow: [ 1,5 ],
        ranges: [{start: moment('2017-11-01','YYYY-MM-DD'),
            end: moment('2017-11-01','YYYY-MM-DD').endOf('month') }]
        $("#calendar1").fullCalendar("renderEvent", newEvent, false);
  });

This is the method I have used so far but still exceed the month. enter image description here

I am new to the jQuery full calendar any guide line please.

Thank you.


Solution

  • "ranges" is not a standard part of fullCalendar's event object.

    Did you perhaps get the idea from an older question, such as this one: Recurring Events in FullCalendar?

    If you want it to work you have to also include the custom code in the eventRender callback, which is the code which reads the data from the ranges and decides whether or not to actually display the event.

    eventRender: function(event){
        return (event.ranges.filter(function(range){ // test event against all the ranges
    
            return (event.start.isBefore(range.end) &&
                event.end.isAfter(range.start));
    
        }).length)>0; //if it isn't in one of the ranges, don't render it (by returning false)
    },