0

I am trying to disable the title in each calendar event. Currently when a user clicks on the event title they are taken to the display page, not the display pop up but an entirely new URL. I want the user to only be able to access the edit pop up form no matter where they click on the event. Example of calendar events In this example the title I am referencing is Non Working. The best I've managed to do is instead of redirecting to a new page refresh the parent which reloads the calendar. I have tried to disable .ms-acal-title using jQuery but with no luck.

This code opens the edit form instead of the display form when the user clicks on the .ms-acal-item which is exactly what I want however, the same approach does not work for the .ms-acal-title.

$("body").on("dblclick click", ".ms-acal-item", function(e){
    e.stopPropagation(); 

    //extract default Event page url and generate new one
    var defaultEventPageUrl = $(this).find('a').attr('href');
    var newEventPageUrl = defaultEventPageUrl.replace('DispEvent.aspx','EditEvent.aspx');

    SP.UI.ModalDialog.showModalDialog({title:"Edit Event",url:newEventPageUrl}); 
});

This code refreshes the parent instead of opening the display page. As you can see I have tried e.preventDefault and e.stopPropagation but this does not prevent the display page from opening.

$("td.ms-acal-title a").attr('disabled', true); 
$("body").on("dblclick click", "ms-acal-sdiv .ms-acal-title a, .ms-acal-ddiv .ms-acal-title a", function(e){
    //e.preventDefault();
    //e.stopPropagation(); 
    parent.window.location.href=parent.window.location.href;
    return false;
});

I tried to use the below code to ban the url and open the edit form but this approach was also unsuccessful.

function disable(){
    var good_links = new Array();
    good_links[0] = "www.google.com";
    links=document.getElementsByTagName('A');
    for(var i=0; i<links.length; i++) {
        if (!inArray(links[i].href, good_links)) {
            links[i].href="#";
            //links[i].href="javascript:return false";
        }
    }
}

function inArray(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(haystack[i] == needle) return true;
    }
    return false;
}

window.onload=disable;

I suspect that I am looking at the wrong element and .ms-acal-title may not be the item which is firing the redirect to the display page.

Any guidance on the correct item to disable or how to stop .ms-acal-title acting as a hyperlink would be much appreciated.

1 Answer 1

0

I slightly modified your first script to override handler once event link is clicked:

  $(".ms-acal-item a").removeAttr("onclick"); //remove original EditLink2 handler
$(document).on('click dblclick','.ms-acal-item a',function(e){
    e.preventDefault();
    //extract default Event page url and generate new one
    var defaultEventPageUrl = $(this).attr('href');
    var newEventPageUrl = defaultEventPageUrl.replace('DispEvent.aspx','EditEvent.aspx');
    SP.UI.ModalDialog.showModalDialog({title:"Edit Event",url:newEventPageUrl}); 
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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