none
Calendar view edit item links RRS feed

  • Question

  • I have a calendar view of a form library in which I just want to show the title of the item.  I do not want users to be able to click on the calendar item and be able to modify the item.  Is there any way to not have calendar items open up with dispform.aspx?

    Thanks
    Tuesday, August 11, 2009 2:48 AM

Answers

  • For a multiday event they put the click event on both the <A> tag and the parent <TD>. A bit redundent...

    So, now the routine checks to see if the <A> tag is inside a <TD> with and "href=" and then fixes it too.

    <script>
    
    function DisableLinks()
    {
     var x = document.getElementsByTagName("A");
     for (var i=0;i<x.length;i++)
     {
      if (x(i).href.indexOf("DispForm.aspx")>-1)
      {
        x(i).onclick = function () {return false};
        x(i).href="javascript:return false";
        if (x(i).parentNode.href) 
        {
          x(i).parentNode.onclick = function () {return false};
          x(i).parentNode.href="javascript:return false";
        }
      }
     }
    }
    
    // add our function to the SharePoint OnLoad event
    _spBodyOnLoadFunctionNames.push("DisableLinks"); 
    
    </script>
    

    Mike Smith TechTrainingNotes.blogspot.com
    • Marked as answer by JRVA_Q Tuesday, August 11, 2009 8:42 PM
    Tuesday, August 11, 2009 8:32 PM

  • > I was wondering if you would know why this method doesn't work in firefox

    Square brackets.....   [i] instead of (i)  I.E. will accept either. Firefox requires square brackets. (I only had Firefox 3.0.6 handy to test with, so let me know if it works in your version)

    <script>
    
    function DisableLinks()
    {
     var x = document.getElementsByTagName("A");
     for (var i=0;i<x.length;i++)
     {
      if (x[i].href.indexOf("DispForm.aspx")>-1)
      {
        x[i].onclick = function () {return false};
        x[i].href="javascript:return false";
        if (x[i].parentNode.href) 
        {
          x[i].parentNode.onclick = function () {return false};
          x[i].parentNode.href="javascript:return false";
        }
      }
     }
    }
    
    // add our function to the SharePoint OnLoad event
    _spBodyOnLoadFunctionNames.push("DisableLinks"); 
    
    </script>
    

    Mike Smith TechTrainingNotes.blogspot.com
    • Marked as answer by JRVA_Q Wednesday, August 19, 2009 9:52 PM
    Wednesday, August 19, 2009 12:30 AM

All replies


  • If you don't want them to open at all...


    On the page with the calendar view:

    Add a Content Editor Web Part
    Edit this web part and set the Chrome to none (to hide the titlebar)
    Click the Source Editor button and paste the following:

    <script>
    
    function DisableLinks()
    {
    var x = document.getElementsByTagName("A");
    for (var i=0;i<x.length;i++)
    {
      if (x(i).href.indexOf("DispForm.aspx")>-1)
      {
        x(i).onclick = function () {alert(1);return false};
      }
    }
    alert(99)
    }
    
    // add our function to the SharePoint OnLoad event
    _spBodyOnLoadFunctionNames.push("DisableLinks"); 
    
    </script>

    This will disable all links to a page with "DispForm.aspx" in the URL.
    You do a little more creative JavaScript work to limit it to a single web part or just calendars.

    Mike Smith TechTrainingNotes.blogspot.com
    Tuesday, August 11, 2009 3:31 AM
  • Hi Mike,

    Thanks for your response.  I think this is on the right track!  However, when a calendar item is clicked on I see the Alert pop up (1 with ok button) from your script, but the navigation still  continues to the dispform url with the edit options for the item. An example of the url is below.

    http://sharepoint/Time%20Off%20Request%20Forms/Forms/DispForm.aspx?ID=87
    Tuesday, August 11, 2009 4:39 PM
  • Duh... I left my debuging code in!  Basically, just remove the alerts.

    <script>
    
    function DisableLinks()
    {
     var x = document.getElementsByTagName("A");
     for (var i=0;i<x.length;i++)
     {
      if (x(i).href.indexOf("DispForm.aspx")>-1)
      {
        x(i).onclick = function () {return false};
      }
     }
    }
    
    // add our function to the SharePoint OnLoad event
    _spBodyOnLoadFunctionNames.push("DisableLinks"); 
    
    </script>

    Mike Smith TechTrainingNotes.blogspot.com
    Tuesday, August 11, 2009 4:44 PM
  • Hey Mike,

    It's not the alerts.  Your script stops the dispform from loading from my list view webparts, but items in the calendar view on the same page still load.  Any ideas?  Thanks for your help

    -Jon
    Tuesday, August 11, 2009 4:50 PM
  • Two mistakes in the same day... time to go home... ;-)

    I left out this line:  x(i).href=""  (while that works, x(i).href="javascirpt:return false" is probably a better practice)

    So:

    <script>
    
    function DisableLinks()
    {
     var x = document.getElementsByTagName("A");
     for (var i=0;i<x.length;i++)
     {
      if (x(i).href.indexOf("DispForm.aspx")>-1)
      {
        x(i).onclick = function () {return false};
        x(i).href = "javascript:return false";
      }
     }
    }
    
    // add our function to the SharePoint OnLoad event
    _spBodyOnLoadFunctionNames.push("DisableLinks"); 
    
    </script>
    

    Mike Smith TechTrainingNotes.blogspot.com
    Tuesday, August 11, 2009 7:01 PM
  • This is really odd, I can hover over the calendar items and see that my browser thinks the link will return "javascript: return false".  However, if I click the link it still takes me to the edit form.  Like I said previously, this works fine for list view webparts.  I wonder if a calendar view can't be defeated in this way.  Darn...
    Tuesday, August 11, 2009 7:39 PM
  • Please restate what you are doing in case I missed something.

    Here's what I tested:
      a document library (you said forms library, but they nearly identical)
      a calendar view of the library
      and a Content Editor Web Part on the calendar view page

    It worked for me...
    Mike Smith TechTrainingNotes.blogspot.com
    Tuesday, August 11, 2009 7:45 PM
  • Mike, 

    Ok I went back and created some new date items.  Single day appointments work fine.  It's just items spanning more than one day load the edit form when clicked.  Can you replicate that?

    I'm the method you describe except with a form library.
    Tuesday, August 11, 2009 7:56 PM
  • For a multiday event they put the click event on both the <A> tag and the parent <TD>. A bit redundent...

    So, now the routine checks to see if the <A> tag is inside a <TD> with and "href=" and then fixes it too.

    <script>
    
    function DisableLinks()
    {
     var x = document.getElementsByTagName("A");
     for (var i=0;i<x.length;i++)
     {
      if (x(i).href.indexOf("DispForm.aspx")>-1)
      {
        x(i).onclick = function () {return false};
        x(i).href="javascript:return false";
        if (x(i).parentNode.href) 
        {
          x(i).parentNode.onclick = function () {return false};
          x(i).parentNode.href="javascript:return false";
        }
      }
     }
    }
    
    // add our function to the SharePoint OnLoad event
    _spBodyOnLoadFunctionNames.push("DisableLinks"); 
    
    </script>
    

    Mike Smith TechTrainingNotes.blogspot.com
    • Marked as answer by JRVA_Q Tuesday, August 11, 2009 8:42 PM
    Tuesday, August 11, 2009 8:32 PM
  • WORKS GREAT!!!! THANKS!
    Tuesday, August 11, 2009 8:42 PM
  • Mike,
    Not sure if you are monitoring this thread, but I was wondering if you would know why this method doesn't work in firefox.  In otherwords, firefox users can still click on the links to get the dispform.aspx for the item.

    Best,

    Tuesday, August 18, 2009 9:10 PM

  • > I was wondering if you would know why this method doesn't work in firefox

    Square brackets.....   [i] instead of (i)  I.E. will accept either. Firefox requires square brackets. (I only had Firefox 3.0.6 handy to test with, so let me know if it works in your version)

    <script>
    
    function DisableLinks()
    {
     var x = document.getElementsByTagName("A");
     for (var i=0;i<x.length;i++)
     {
      if (x[i].href.indexOf("DispForm.aspx")>-1)
      {
        x[i].onclick = function () {return false};
        x[i].href="javascript:return false";
        if (x[i].parentNode.href) 
        {
          x[i].parentNode.onclick = function () {return false};
          x[i].parentNode.href="javascript:return false";
        }
      }
     }
    }
    
    // add our function to the SharePoint OnLoad event
    _spBodyOnLoadFunctionNames.push("DisableLinks"); 
    
    </script>
    

    Mike Smith TechTrainingNotes.blogspot.com
    • Marked as answer by JRVA_Q Wednesday, August 19, 2009 9:52 PM
    Wednesday, August 19, 2009 12:30 AM
  • Mike, you are the man. THanks
    Wednesday, August 19, 2009 9:52 PM
  • Hi Mike,


    I was wondering if you could me with a similar issue.

    I actually WANT the DispForm.aspx to come up when an end user clicks on an item in a calendar view, but the EditForm.aspx comes up instead.

    Everything works great in my development environment (this wasn't something I was even 'developing', it's part of the ootb site), but when I packaged up the site as a template and installed it in production, the calendar seems to have gone awry.  Everything between the two enviroments appear the same, but whenever I have a calendar view (regardless of list, I did try a different list), the onclick event of the list item brings up the EditForm instead of the DispForm.

    I also went into SPD and changed the "Supporting Files" for the list.  The items do not seem to respond to this either.  They still go to the EditForm regardless of what is set in the "Supporting Files" for the list.

    Do you have any knowledge on how the calendar view is built to display the EditForm.aspx instead of the default (at least I think it is the default) DispForm.aspx?

    Don't mean to step on someone else's thread, but I cannot seem to find anyone who has any knowledge on the calendar view.

    Thanks,

    Keith

    Keith Oswalt
    Friday, October 9, 2009 3:08 PM
  • Keith,

    Does this happen with all calendars, or just one?  What happens when you create a new calendar in the production site?  Also are the development and production environments both at the same service pack / patch levels?


    Mike Smith TechTrainingNotes.blogspot.com
    Tuesday, October 13, 2009 12:55 AM