Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FullCalendar - how to disable prev button

How do you disable the prev button when the previous month is less than the current month?

For instance, if the current month is August, then I want to disable the prev month button so that you cannot see the month of July.

like image 935
thd Avatar asked Aug 31 '10 22:08

thd


People also ask

How do I remove the Today button from FullCalendar?

fc-next-button'); $('body'). remove('. fc-today-button'); } });

How do I delete a FullCalendar event?

Event::remove Removes an event from the calendar. You must call this on an Event Object that you received elsewhere in the API, such as getEventById.

How do I set events in FullCalendar?

Here is an example of how to specify an array of events: var calendar = new Calendar(calendarEl, { events: [ { title : 'event1', start : '2010-01-01' }, { title : 'event2', start : '2010-01-05', end : '2010-01-07' }, { title : 'event3', start : '2010-01-09T12:30:00', allDay : false // will make the time show } ] });

How do I select multiple dates in FullCalendar?

Detect when the user clicks on dates or times. Give the user the ability to select multiple dates or time slots with their mouse or touch device. Allows a user to highlight multiple days or timeslots by clicking and dragging.


2 Answers

The code checks for fc-state-disabled or ui-state-disabled so there is no need to disbled the button.

viewRender: function( view, element ) {
    // Drop the second param ('day') if you want to be more specific
    if(moment().isAfter(view.intervalStart, 'day')) {
        $('.fc-prev-button').addClass('fc-state-disabled');
    } else {
        $('.fc-prev-button').removeClass('fc-state-disabled');
    }
}
like image 146
bobartlett Avatar answered Sep 30 '22 17:09

bobartlett


You can do this easily by yourself, here is an example that works.

I have done this by changing fullcalendar.js. Note that in many examples you can change the year, month and day using the prev/next buttons. Each of these have their own render function so this would need to be taken in to consideration if you want it for each of these. My example can easily be adapted.

In my example I also set the previous button to the color red when it is "disabled". You can decide yourself on how you want to do with this.

views.month = function(element, options, viewName) {
    return new Grid(element, options, {
        render: function(date, delta) {
            if (delta == -1) {
                var curr_date = new Date();
                var curr_m = curr_date.getMonth();
                if (date.getMonth() < curr_m) {
                    return false;
                } else if ((date.getMonth() - 1) < curr_m) {
                    $(".fc-button-prev span").css("background", "red");
                } else {
                    $(".fc-button-prev span").css("background", "#E8E8E8");
                }               
            } else {
                $(".fc-button-prev span").css("background", "#E8E8E8");
            }

This starts from line :944 in fullcalendar.js

I have tested this in Firefox 3.6.8 using the examples basic-view.html and default.html provided when you download FullCalendar. Simply change:

<script type='text/javascript' src='../fullcalendar.min.js'></script>

to

<script type='text/javascript' src='../fullcalendar.js'></script>
like image 24
going Avatar answered Sep 30 '22 18:09

going