admin管理员组

文章数量:1287561

I am using the Full Calender js plugin, so far so good. but i want to check if a selection between the start and end has events?

I just need a true or false returned. Basically i want to stop users from creating events if an even already exists on the date selection.

var calendar = $('#calendar').fullCalendar({

    selectable: true,
    selectHelper: true,
    firstDay: 5,
    weekNumbers: false,
    select: function (start, end, allDay, event) {
        var TitleSet = false;
        StartDate = start;
        EndDate = end;
        if (event) {}
        if (TitleSet) {
            calendar.fullCalendar('renderEvent', {
                title: title,
                start: start,
                end: end,
                allDay: allDay
            },
            true // make the event "stick"
            );
        }
        calendar.fullCalendar('unselect');

    },
    editable: true,
    events: EventsArr,
    eventRender: function (event, element) {
        element.qtip({
            content: event.description
        });
    }
});

I am using the Full Calender js plugin, so far so good. but i want to check if a selection between the start and end has events?

I just need a true or false returned. Basically i want to stop users from creating events if an even already exists on the date selection.

var calendar = $('#calendar').fullCalendar({

    selectable: true,
    selectHelper: true,
    firstDay: 5,
    weekNumbers: false,
    select: function (start, end, allDay, event) {
        var TitleSet = false;
        StartDate = start;
        EndDate = end;
        if (event) {}
        if (TitleSet) {
            calendar.fullCalendar('renderEvent', {
                title: title,
                start: start,
                end: end,
                allDay: allDay
            },
            true // make the event "stick"
            );
        }
        calendar.fullCalendar('unselect');

    },
    editable: true,
    events: EventsArr,
    eventRender: function (event, element) {
        element.qtip({
            content: event.description
        });
    }
});
Share Improve this question edited Feb 27, 2014 at 11:38 Tomanow 7,3773 gold badges28 silver badges52 bronze badges asked Feb 27, 2014 at 11:35 PomsterPomster 15.2k55 gold badges132 silver badges207 bronze badges 4
  • 1 ok where are your events stored? what have you tried? try to be clearer, add more details... – CodeBird Commented Feb 27, 2014 at 11:42
  • Events are stored in my database and called into and array, events: EventsArr – Pomster Commented Feb 27, 2014 at 11:45
  • 1 possible duplicate of Can I prevent events with conflict time? – MarCrazyness Commented Feb 27, 2014 at 17:24
  • You will need to create a method to get the array of events already loaded in calendar, after that use that array to get all days that have events and if user clicks on one of that dates don´t let create another event. This is something that only you can make and figure out, you will need to make an algorithm for yourself... – Henrique C. Commented Mar 3, 2014 at 9:20
Add a ment  | 

2 Answers 2

Reset to default 8

I tried this methode and it looks fine

    // check if this day has an event before
    function IsDateHasEvent(date) {
        var allEvents = [];
        allEvents = $('#calendar').fullCalendar('clientEvents');
        var event = $.grep(allEvents, function (v) {
            return v.start === date;
        });
        return event.length > 0;
    }

then you can call it from dayclick event

    dayClick: function (date, allDay, jsEvent, view) {
                        
        if (!IsDateHasEvent(date)) {
            selectedDate = date;
            $("#divAddNewAppointment").dialog("open");
        }
        else {
            $('<%= "#" + lblMessage.ClientID%>').html(" your error msg");
            $("#divMessage").dialog("open");
        }
    }

You will need to create a method to get the array of events already loaded in calendar, after that use that array to get all days that have events and if user clicks on one of that dates don´t let create another event. This is something that only you can make and figure out, you will need to make an algorithm for yourself...

Check this clientEvents

本文标签: javascriptFullCalender check if selection days has an eventStack Overflow