3

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
        });
    }
});
Tomanow
  • 7,247
  • 3
  • 24
  • 52
Pomster
  • 14,567
  • 55
  • 128
  • 204
  • 1
    ok where are your events stored? what have you tried? try to be clearer, add more details... – CodeBird Feb 27 '14 at 11:42
  • Events are stored in my database and called into and array, events: EventsArr – Pomster Feb 27 '14 at 11:45
  • 1
    possible duplicate of [Can I prevent events with conflict time?](http://stackoverflow.com/questions/15800398/can-i-prevent-events-with-conflict-time) – MarCrazyness Feb 27 '14 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. Mar 03 '14 at 09:20

2 Answers2

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");
        }
    }
Majid Basirati
  • 2,665
  • 3
  • 24
  • 46
Zakaria
  • 1,055
  • 12
  • 16
0

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

Henrique C.
  • 948
  • 1
  • 14
  • 36