Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable event creation on Weekends

I am trying to use Fullcalendar for one of my leave application. I have select option enabled so that the user can select dates and apply leave on it. But I want to disable weekends from getting selected, ie it should give a alert when the user clicks on the weekends. Is it achivable?

My code

this.calendarOptions = {
    height:450,
    defaultDate: moment(new Date(),'YYYY-MM-DD'),
    editable: false,
    stick:true,
    selectable:true,
    eventLimit: false, // allow "more" link when too many events
    events: this.eventList,
    header: {
        left: 'month basicWeek basicDay',
        center: 'title',
        right: 'today prev,next'
    },
    displayEventTime: false,

    select: (start, end, allDay) => {
        this.startDate=moment(start).format("YYYY-MM-DD");
        this.endDate=moment(end).format("YYYY-MM-DD");   
        $('.first.modal').modal('show');
    },
    dayRender: (date, cell)=> {
    //logic
    },
    selectOverlap:false,
};
like image 993
Vikhyath Maiya Avatar asked Oct 22 '25 02:10

Vikhyath Maiya


1 Answers

You can do that on the select method. Just go from the startDate to the endDate and check if any of those days are weekends. If so, display the alert / popup and return false.

select: (start, end, allDay) => {
    var startDate = moment(start),
    endDate = moment(end),
    date = startDate.clone(),
    isWeekend = false;

    while (date.isBefore(endDate)) {
        if (date.isoWeekday() == 6 || date.isoWeekday() == 7) {
            isWeekend = true;
        }    
        date.add(1, 'day');
    }

    if (isWeekend) {
        alert('can\'t add event - weekend');

        return false;
    }

    this.startDate= startDate.format("YYYY-MM-DD");
    this.endDate= endDate.format("YYYY-MM-DD");   

    //$('.first.modal').modal('show');
},

See fiddle.

like image 63
Luís Cruz Avatar answered Oct 24 '25 08:10

Luís Cruz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!