tampe125
tampe125

Reputation: 8543

Dragging an event with url always follow the url after the drop

I'm having some troubles while dragging an event with an url assiociated.

If you try to do that, you'll see that the event correctly moves, but also the click event is fired, so you'll visit the linked url (and that's bad).

I tried playing around with the eventClick callback, but with no luck.
Here you can find my code:

// calendar setup
eventDragStart : function(event, jsEvent, ui, view){
    event.dragging = true;
},
eventDragStop : function(event, jsEvent, ui, view){
    event.dragging = false;
},
eventClick : function(event, jsEvent, view){
    //even if I try to return always false, the link is still active
    if(event.dragging === true) return false;
},

Then i tried to manipulate the event link:

eventRender : function(event, element, view){
    $('a').click(function(){
    // custom function that checks if the event is being dragged or not
    //return dragCheck(event);
    return false;
    });
},

but still no luck. I think that while dragging, a new element is created, so every custom value is wiped out...

Any ideas?

Upvotes: 1

Views: 193

Answers (1)

tampe125
tampe125

Reputation: 8543

- Doctor, when I punch my stomach I feel bad
- So, don't punch it!

I found a solution following the previous motto.
Instead of using the original url property, I created another one custom_url.
This will prevent fullcalendar from creating the a element, so the problem is gone.

Here you can find my code.

Server side code for fetching the events:

foreach($this->items as $row)
{
    $event = array();
    $event['id']         = $row->id_calendars;
    $event['title']      = $row->cal_title;
    $event['start']      = $row->cal_start;
    $event['end']        = $row->cal_end;
    $event['allDay']     = (bool) $row->cal_all_day;
    $event['custom_url'] = $row->url;

    $events[] = $event;
}

echo json_encode($events);

Then the javascript part:

eventDragStart : function(event, jsEvent, ui, view){
      event.dragging = true;
},
eventDragStop : function(event, jsEvent, ui, view){
      event.dragging = false;
},
eventClick : function(event, jsEvent, view){
      if(event.dragging === true) return false;

      if(event.custom_url){
            window.location = event.custom_url;
      }
},

And you're done!

Upvotes: 2

Related Questions