Skip to content

Instantly share code, notes, and snippets.

@juanbrujo
Last active August 14, 2024 05:32
Show Gist options
  • Save juanbrujo/c4a0a8d36fc64860f487 to your computer and use it in GitHub Desktop.
Save juanbrujo/c4a0a8d36fc64860f487 to your computer and use it in GitHub Desktop.
jQuery FullCalendar.js: disable prev/next button for past/future dates
$('#calendar').fullCalendar({
viewRender: function(currentView){
var minDate = moment(),
maxDate = moment().add(2,'weeks');
// Past
if (minDate >= currentView.start && minDate <= currentView.end) {
$(".fc-prev-button").prop('disabled', true);
$(".fc-prev-button").addClass('fc-state-disabled');
}
else {
$(".fc-prev-button").removeClass('fc-state-disabled');
$(".fc-prev-button").prop('disabled', false);
}
// Future
if (maxDate >= currentView.start && maxDate <= currentView.end) {
$(".fc-next-button").prop('disabled', true);
$(".fc-next-button").addClass('fc-state-disabled');
} else {
$(".fc-next-button").removeClass('fc-state-disabled');
$(".fc-next-button").prop('disabled', false);
}
}
});
@SnehaK13
Copy link

how can i disable previous button that user not to enter past date?
i'd used this condition,but its not working
if($("#startdatepicker1").datepicker("getDate").getDate() < today)

@iigormello
Copy link

Thank you, I was in great need of this solution.

@paolobroccardo
Copy link

Clean and simple solution that worked perfectly from the go. Thanks!

@UA
Copy link

UA commented Jul 4, 2018

Thanks!

@browndemon
Copy link

browndemon commented Sep 1, 2019

If they need to disappear with the buttons just assign to the Header as follows.

header: {
   left: '',
   center: 'title',
   right: ''
 },

@dmitriievv
Copy link

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment