2

How can I change the event's URL in the eventClick? I change it but when I updateEvent on the calendar it doesn't take my change it has the original value.

var path = window.location.origin + window.location.pathname + calEvent.url;
calEvent.url = path;
//update the calEvent
$('#calendar').fullCalendar('updateEvent', calEvent);
Jon
  • 9,156
  • 9
  • 56
  • 73
ARivera618
  • 25
  • 7

1 Answers1

1

By the time eventClick runs it's too late, you already clicked on the event and the redirection to the location specified in the existing event URL has already started.

If you want to manipulate the URL values coming from the server I suggest you do this in the eventDataTransform callback, which runs before each event is rendered onto the calendar, e.g.:

eventDataTransform: function( eventData ) {
    eventData.url = window.location.origin + window.location.pathname + eventData.url;
    return eventData;
},

See https://fullcalendar.io/docs/event_data/eventDataTransform/ for a bit more detail on the callback.


However, I don't know exactly what format your URLs are in but I sense that your code is actually unnecessary. I think for it to make sense you must be outputting relative URLs into the calendar data e.g. "test.php" or "images/test.jpg".

If you leave these as they are and click on them, the browser will automatically prepend the current site address onto them before trying to navigate there. The code you're running just hard-codes what the browser will do automatically, and I don't think you need to bother.

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • Thank you so much your eventDataTransform fixed my issue. – ARivera618 Feb 22 '18 at 18:34
  • No problem. In that case please remember to mark the answer as "accepted" (by clicking the tick next to the question so it turns green) - thanks. – ADyson Feb 22 '18 at 18:49
  • P.S. I still think this code may be redundant entirely. What happens if you just delete it? – ADyson Feb 22 '18 at 18:49
  • The problem is that the url is being created in a mvc controller class and has a path of /PreAnalysis/Index?id= and the it drops BOR from the path which is appDev01/BOR/PreAnalysis/Index?id= so when I use the window.location it builds it perfectly. I spent a lot of time trying to resolve the issue and that was the only solution I could get to work. – ARivera618 Feb 22 '18 at 19:15
  • how do you generate the URLs in MVC? Probably you should be using a URLHelper to do it, so that it creates the right URL for your environment. For example see https://stackoverflow.com/questions/699782/creating-a-url-in-the-controller-net-mvc – ADyson Feb 22 '18 at 21:22