Tuesday, May 12, 2015

Hiding the SharePoint columns on the DisplayForm.aspx or EditForm.aspx

SharePoint list columns can be made hidden from the Content Type settings but sometimes we need to hide a column only from the DisplayForm.aspx or EditForm.aspx and not both. The out of the box functionality hide the columns from both forms.

The javascript snippet in a CEWP can hide the columns. Make sure the CEWP should be added at the end of the page.

<script type="text/javascript">
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 ;
}
}

HideField("All Day Event");
HideField("Recurrence") ;
HideField("Workspace") ;
</script>

No comments: