Hiding Recurrence, workspace and all day event columns in a SharePoint Calendar List – Part1

Hiding a column in a SharePoint list had never been a big thing. You get the option to manage the content type and make the columns required, optional or hidden. Pretty simple, huh!

But have you ever tried this for a calendar list. Because it’s this calendar list that gave me the reason for this post.

Preface

I got this requirement in a calendar list to hide the start time, end time, all day event and workspace columns. On checking the columns in the event content type of a Calendar list, I found that there are two categories of site columns – one set that appears as link and the other set which appears as plain text.

hideCol5

The columns that are links, for them appearance could be changed easily by making the column setting as hidden/optional/required.

However, there was no such option for columns such as Recurrence, All Day Event and Workspace. So how do we hide such columns, since I didn’t want any of it to be visible on my forms.

 

Solution

In the calendar tab, go to the form web parts and modify the “Default New Form” web part.

hideCol6

Add a content editor web part and add the below JavaScript to hide the column All Day Event and Workspace.

</p>
<p>&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;

&lt;!--

// This is custom functionality that hides selected columns in the a list.</p>
<p>_spBodyOnLoadFunctionNames.push(&quot;hideFields&quot;);

function findacontrol(FieldName) {

 var arr = document.getElementsByTagName(&quot;!&quot;);

 // get all comments

 for (var i=0;i &lt; arr.length; i++ )

 {

 // now match the field name

 if (arr[i].innerHTML.indexOf(FieldName) &gt; 0)

 { return arr[i]; }

 }

}

function hideFields() {

 var control = findacontrol(&quot;All Day Event&quot;);

 control.parentNode.parentNode.style.display=&quot;none&quot;;

 control = findacontrol(&quot;Workspace&quot;);

 control.parentNode.parentNode.style.display=&quot;none&quot;;

 }

//end custom functionality--&gt;&lt;/script&gt;</p>
<p>

Stop editing and add a new item. There you go, you can see the change that the two columns have vanished.

hideCol7

 

Now this change was done in just the Default New Form web part. To see the change in Display and Edit form as well, you need to repeat the same set of steps for their respective default web parts.

Now instead of pasting the same piece of JavaScript code in the three content editor web parts (CEWP) in three forms, the better idea would be to have a text file with that code saved in the Site Assets library and have a reference of that file in the CEWP.

You can notice that the columns are hidden now in all forms i.e. New, Edit and Display.

Yoohoo!!!

 

 

 

Advertisements

7 thoughts on “Hiding Recurrence, workspace and all day event columns in a SharePoint Calendar List – Part1

  1. Pingback: Hiding Recurrence, workspace and all day event columns in a SharePoint Calendar List – Part2 | My Learnings

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s