Showing posts with label Hide Field. Show all posts
Showing posts with label Hide Field. Show all posts

Tuesday, December 27, 2011

Hide Columns in NewForm.aspx / EditForm.aspx / DispForm.aspx

Hide SharePoint Columns in New / Edit / View Form
Open the SharePoint Designer 2010, Go to the Corresponding List/ Library.

Open the New/Edit / View Item Aspx Page in Edit In Advance Mode add the Following script



<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">

Now copy & paste this JavaScript code after above mentioned tag :

<script language="javascript" type="text/javascript">
_spBodyOnLoadFunctionNames.push("hideFields");
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];      }
   }
}

function hideFields() {
   var control = findacontrol("Title");
   control.parentNode.parentNode.style.display="none";
   control = findacontrol("Document Link");
   control.parentNode.parentNode.style.display="none";
   control = findacontrol("PublishDate");
   control.parentNode.parentNode.style.display="none";
}
</script>

Friday, April 8, 2011

Hiding fields on NewForm.aspx and EditForm.aspx

First open entry form (NewForm.aspx / EditForm.aspx / DispForm.aspx) in advanced mode in sharepoint designer. Then search for tag :

<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">

Now copy & paste this JavaScript code after this tag :

<script type="text/ecmascript">

 ExecuteOrDelayUntilScriptLoaded(runCode, "sp.js");
 function runCode()
 {
  HideField("Expose to Customer / Partner",true);
                HideField("Reported By",true);              
                HideField("Reported Date",true);
 }

 // Function To Hide Fields
   function HideField(title,hide){
     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++)
         {
           var mHead=title+"<SPAN class=ms-formvalidation> *</SPAN>";
           if(el.childNodes[j].innerHTML == title || el.childNodes[j].nodeValue == title || el.childNodes[j].innerHTML==mHead)
           {
             var elRow = el.parentNode.parentNode ;
             if(hide==true)
             {
              elRow.style.display = "none"; //and hide the row
             }
             else
             {
              elRow.style.display = "visible"; //and show the row
             }
             foundField = true ;
             break;
           }
         }
       }
       if(foundField)
        break ;
     }
   }
 
</script>