Tuesday, January 20, 2015

Hide All Day Event and Recurrence fields from calendar in SharePoint 2013

How to simple hide fields "All Day Event" and "Recurrence" from SharePoint calendar with javascript? Here is a solution.


Open your Calendar.
Navigate to Calendar tab->expand Form Web Parts->and click on Default New form.







In Default New form edit page, click on Add a Web Part and select the Content Editor Web part.










From Content Editor Web part, Click on Click here to add new Content.










Now select Edit Source from ribbon and add java script to HTML

<script type="text/javascript">

_spBodyOnLoadFunctionNames.push("hideall()");
function hideall()
{
HideField("Recurrence");
HideField("All Day Event");
}

function HideField(title){
var header_h3=document.getElementsByTagName("h3") ;

for(var i = 0; i <header_h3.length; i++)
{
   var el = header_h3[i];
   var foundField ;
  if(el.className=="ms-standardheader")
   {
       for(var j=0; j<el.childNodes.length; j++)
       { 
           if(el.childNodes[j].innerHTML == title || el.childNodes[j].nodeValue == title)
           { 
               var elRow = el.parentNode.parentNode ;
               elRow.style.display = "none"; //and hide the row
               foundField = true ;
               break;
           }
       }        
   }
   if(foundField)
       break ;
}
}
</script>
Save.
That's it!

9 comments:

  1. This script does nothing to my list. It doesn't hide the fields.
    I am using SP2013.
    Any thoughts?

    ReplyDelete
    Replies
    1. I tried again in my lab environment and working fine.

      Check your language of site, if not on English change the column name "Recurrence" and "All Day Event" in the language of the site.

      Delete
  2. The script above works for on premise, for SharePoint Online you will need to change the following two lines

    Change: var header_h3=document.getElementsByTagName("h3") ;
    to: var header_h3=document.getElementsByTagName("span") ;

    and

    Change: if(el.className=="ms-standardheader")
    to: if(el.className=="ms-h3 ms-standardheader")

    Hope this help.

    ReplyDelete
    Replies
    1. This SharePoint Online modification works for me. Many thanks!

      Delete
    2. Same for me! Thank you!

      Delete
  3. This worked perfectly "as is" for me - Thank You!!

    ReplyDelete
  4. Nice! Just what I was looking for

    ReplyDelete
  5. Worked perfectly! NOTE: I am not an experienced Sharepoint user nor java script writer, and I was even to figure this out. Thank you!

    ReplyDelete