Jquery fullcalendar

I am trying to integrate the full jquery calendar plugin. And I want to disable past dates for selection. Therefore, I can only select dates starting from the current date. How is this possible? How can I filter dates and specify a condition. I am new to jquery.

$(document).ready(function() { var date = new Date(); var d = date.getDate(); var m = date.getMonth(); var y = date.getFullYear(); var calendar = $('#calendar').fullCalendar({ header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' }, selectable: true, selectHelper: true, select: function(start, end, allDay) { var title = prompt('Event Title:'); if (title) { calendar.fullCalendar('renderEvent', { title: title, start: start, end: end, allDay: allDay }, true // make the event "stick" ); } calendar.fullCalendar('unselect'); }, editable: true, }); }); 
+8
jquery jquery-plugins fullcalendar
source share
2 answers

In the selection method, you are given the selected start and end date, and earlier in the method you received the current date in the date variable. So just compare them, and if it's less than date , handle the error.

 select: function(start, end, allDay) { if(start < date) { // Do whatever you want here. alert('Cannot select past dates.'); return; } var title = prompt('Event Title:'); if (title) { calendar.fullCalendar('renderEvent', { title: title, start: start, end: end, allDay: allDay }, true // make the event "stick" ); } calendar.fullCalendar('unselect'); }, 
+5
source share

Note regarding Brandon's answer, a popup will also appear if you click on the current date. You will need to check if the user clicked today:

 if (start < date && start.getDate() != date.getDate() ) { alert('Cannot select past dates.'); return; } 
+1
source share

All Articles