1

In SP2013 is it possible to customize the "create" links for different calendar views of the same list?

When I hover over the calendar view cell and the "New item"-Link appears, I would like to navigate to

  • NewItem_A.aspx from calendar view A
  • NewItem_B.aspx from calendar view B
1

Hack 1: Overriding link on mouseenter

In the end I resorted to the following hack:

// requires jQuery
$(document).ready(function() {
  $("#WebPartWPQ1").on("mouseenter", "a[evtid='new_item']", function(evt) {
    var $link = $(this);
    $link.unbind(); // Unbind any standard sharepoint event handlers
    $link.attr("href", "http://linkToMyCustomForm");
  });
}

where #WebPartWPQ1 is the calendar webpart's container ID.

This snippet registers when the mouse is moved over the "new item link" inside the webpart and replaces the link target with the custom link.

The problem of this solution is that the currently displayed date in the calendar view does not get propagated to the form.

Alternative: Using the obfuscated javascript "API"

function(instanceId, link) {
  // wellknown object provided by sharepoint.
  // It's the very last javascript callback after loading and initializing the page
  // This ensures that the CalendarInstanceRepository has been initialized
  window.Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function(){
    window.SP.UI.ApplicationPages.CalendarInstanceRepository
      .$w[instanceId] // $w    - member with the internal array of registered calendar views
      .$B_1           // $B_1: - instance of SP.UI.ApplicationPages.CalendarNewFormDialog
      .$4w_1 = link;  // $4w_1 - new item link property
  });
};

where instance Id would be set to WPQ1 for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.