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.
You can use this:
var start_date= $.fullCalendar.formatDate(start,'YYYY-MM-DD');
var today_date = moment().format('YYYY-MM-DD');
if(check < today)
{
alert("Back date event not allowed ");
$('#calendar').fullCalendar('unselect');
return false
}
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.
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
In Fullcalendar i achieved it by dayClick event. I thought it is the simple way to do it.
Here is my code..
dayClick: function (date, cell) {
var current_date = moment().format('YYYY-MM-DD')
// date.format() returns selected date from fullcalendar
if(current_date <= date.format()) {
//your code
}
}
Hope it helps past and future dates will be unselectable..
I have tried this approach, works well.
$('#calendar').fullCalendar({
defaultView: 'month',
selectable: true,
selectAllow: function(select) {
return moment().diff(select.start) <= 0
}
})
Enjoy!
In fullcalendar 3.9, you might prefer the validRange function parameter :
validRange: function(nowDate){
return {start: nowDate} //to prevent anterior dates
},
Drawback: this also hides events before that datetime