Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make past date unselectable in fullcalendar?

Problem is, how to disable selectable on PAST DATES in fullcalendar's month/week view.

I want to user not allowed to click/select the on past dates.

enter image description here

Here is some googled code snippet I am trying to implement on event rendering:

selectable: true, selectHelper: false, select: function(start, end, allDay) {         var appdate = jQuery.datepicker.formatDate('<?php echo $DPFormat; ?>', new Date(start));         jQuery('#appdate').val(appdate);         jQuery('#AppFirstModal').show();     },     eventRender: function(event, element, view)     {         var view = 'month' ;        if(event.start.getMonth() !== view.start.getMonth()) { return false; }     }, 

But its not working though.

I tried bellow CSS too and this help me to hide past date text only, but selectable is still working on pastdate box.

.fc-other-month .fc-day-number {      display:none; } 

I am really stuck with this problem. Please someone help me out. Thanks...

like image 298
Frank Avatar asked Feb 20 '13 11:02

Frank


People also ask

How do I change the date on fullCalendar?

The calendar's dates can change any time the user does the following: click the prev/next buttons, change the view, click a navlink. The dates can also change when the current-date is manipulated via the API, such as when gotoDate is called. datesSet is called after the new date range has been rendered.

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.

How do you get a clicked date in fullCalendar?

click(function(){ var fetchDate = $(this). data("date"); $("#displayDate"). text(fetchDate); });

How do I hide time in fullCalendar?

This option is available from v2. 4.0 see fullcalendar.io/docs/text/displayEventTime - You need to set it as option of fullCalendar and it affects all events. Or use CSS . fc-time{ display : none; } .


2 Answers

I have done this in my fullcalendar and it's working perfectly.

you can add this code in your select function.

 select: function(start, end, allDay) {     var check = $.fullCalendar.formatDate(start,'yyyy-MM-dd');     var today = $.fullCalendar.formatDate(new Date(),'yyyy-MM-dd');     if(check < today)     {         // Previous Day. show message if you want otherwise do nothing.         // So it will be unselectable     }     else     {         // Its a right date         // Do something     }   }, 

I hope it will help you.

like image 125
Mausami Avatar answered Nov 16 '22 03:11

Mausami


I like this approach:

select: function(start, end) {     if(start.isBefore(moment())) {         $('#calendar').fullCalendar('unselect');         return false;     } } 

It will essentially disable selection on times before "now".

Unselect method

like image 38
Michal Gallovic Avatar answered Nov 16 '22 03:11

Michal Gallovic