Tuesday 28 August 2012

Script to Hide Workspace field in Calendar NewForm

The User can create a calendar using Calendar Template in SharePoint. The user can add the daily details in the calendar. To add the details the user clicks on "Add" link & the NewForm.aspx page opens to enter the details of the item as shown below.



Now the admin does not want the user to create his own workspace. So the Workspace field should not be visible to the user. To hide the Workspace field open the NewForm.aspx page in seperate tab. Now edit the page & add a CEWP & add the following javascript in the CEWP.


<script language="javascript" type="text/javascript">
 
_spBodyOnLoadFunctionNames.push("hideWorkSpacefield");

function hideWorkSpacefield()
{
     var control = findacontrol("Workspace");
   control.parentNode.parentNode.style.display="none";
}

function findacontrol(FieldName) 
{
   var arr = document.getElementsByTagName("!");
   // get all comments
   for (var i=0;i < arr.length; i++ )
   {
      // now match the field name
      if (arr[i].innerHTML.indexOf(FieldName) > 0)
      {         return arr[i];      }
   }
}

</script>

The above script hides the Workspace field whenever the user clicks on the NewForm.aspx page as shown below.



No comments:

Post a Comment