Reputation: 4523
I have Dates like:
Start Date : 2013-12-04
End Date : 2013-12-06
Now I want to put a restriction that Smaller Date should not be Dragged after Bigger Date and Bigger Date should not be dragged before smaller Date.
Is this possible to implement ?
Here is my code so far:
$(document).ready(function() {
$('#calendar').fullCalendar({
editable: true,
events: "json-data.php",
eventDrop: function(event, delta) {
alert(event.title + ' was moved ' + delta + ' days\n' +
'(Dragged)');
},
loading: function(bool) {
if (bool) $('#loading').show();
else $('#loading').hide();
}
});
});
Upvotes: 0
Views: 38
Reputation: 7328
You can use 'revertFunc' (documentation here)
Put something like this in eventDrop
if (initialDate.getTime()>finalDate.getTime()) {revertFunc();}
getTime
is to get the number of milliseconds passed since 1970(this is used for comparing two dates)
And by initialDate
and finalDate
I'm referring to the initial(drag start) and final(drag end) Date
instances. In this case you can probably replace that init/final check by
if (dayDelta<0)
dayDelta
is predefined in fullcalendar
Upvotes: 1
Reputation: 52151
As shown in the documentation on eventDrop
: the eventDrop
callback receives among its arguments a revertFunc
function, which, when called, reverts the event back to its original position.
Here is an outline of how you can write your eventDrop
callback :
eventDrop : function(event,dayDelta,minuteDelta,allDay,revertFunc) {
var smaller = /* get date of (moved) smaller event */,
bigger = /* get date of (moved) bigger event */;
if ( smaller > bigger ) {
alert('smaller should stay before bigger');
revertFunc();
}
}
Upvotes: 1