PHPMachine
PHPMachine

Reputation: 43

possible bug with fullCalendar gotoDate and getDate

I do not want people trying to create an event in the past in my fullCalendar. So, once they select a date/time, I do a quick check as follows:

select: function(start, end, allDay) { 
        // need to check the day first. If the selected day/time < today, throw an alert
        // otherwise allow the booking of the conference.
            var now = calendar.fullCalendar('getDate');
            if (start < now )
            {
                alert('You cannot book a conference in the past!' +start +now);
                calendar.fullCalendar( 'unselect' );
            }
            else
            {
                             // other stuff here
                            }

and this works great. If I click on a time or date that is earlier than right now, I get an alert saying I can't do that. Perfect right?

I'm using jQuery DatePicker, I can click on a date in a small calendar view and go to that date in my fullCalendar which is defaulted to an agenda only view. It works quite well:

$( "#datepicker" ).datepicker({
        changeMonth: true,
        changeYear: true,
        minDate: 0, 
        maxDate: "+1Y",
        onSelect: function(dateText) {
            // fullCalendar only accepts a date in a specific format so parse the date
            // from the jQuery DatePicker widget and use that result to move the calendar
            // to the correct day.
            var pd = $.fullCalendar.parseDate(dateText);
            $('#calendar').fullCalendar('gotoDate', pd);
        }

    });

This routine puts me in the correct week in the agenda view. I can then select a date to work with in that week. HOWEVER, if I try to create an event on a date PRIOR to the date I went to with the gotoDate method, I ALSO get an error about creating events in the past. It seems the 'gotoDate' method is virtually SETTING the date. I can create events on that date or later, but not prior to that date.

If I just use fullCalendar's navigation methods, it works perfectly as it should. But since, fullCalendar doesn't have a 'jump to date' option or widget, I created by own using the DatePicker which I thought was a logical thing to do.

So, is this a bug? or am I doing something completely wrong?

Upvotes: 0

Views: 3054

Answers (1)

PHPMachine
PHPMachine

Reputation: 43

Yes, Answering my own question thanks to comments by Kyoka and Ganeshk. as it happens, the fullCalendar('getDate') function returns the currently selected date as opposed to "today". This is just a mis-understanding of docs on my part. The solution then, is to use a new Date object, in which case it works perfectly:

select: function(start, end, allDay) { 
    // need to check the day first. If the selected day/time < today, throw an alert
    // otherwise allow the booking of the conference.
        var now = new Date();
        if (start < now )
        {
            alert('You cannot book a conference in the past!');
            calendar.fullCalendar( 'unselect' );
        }
        else
        {
                         // other stuff here
                        }

Hope this is a help to others as well.

Upvotes: 2

Related Questions