Wednesday, May 6, 2015

Hide col in List edit and new form






Please use the following PowerShell Script to hide the column from New and Edit forms.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$web = Get-SPWeb "http://sp2013" # Site where your list exists
$list = $web.Lists.TryGetList("EmergencyContacts") #list name
if($list)
{
    $field = $list.Fields["Phone"] #internal field name
    $field.ShowInNewForm = $false
    $field.ShowInEditForm = $false
    $field.Update()
}
Alternate option is to customize the New and Edit form using SharePoint Designer.  Remove the columns tag.  In my suggestion best to use the PowerShell script to hide the columns for New and Edit form.  If you want to enable later, please change the script to true, it will be shown without any effor.
Please mark it answered, if your problem resolved or helpful.


$web = Get-SPWeb webUrl
$list = $web.Lists.TryGetList("Listname")
if($list)
{
    $field = $list.Fields["FieldName"]
    $field.ShowInNewForm = $false
    $field.Update()
}


<script type="text/javascript">
$(document).ready(function() {
    $('nobr:contains("Completion time")').closest('tr').hide();
    $('nobr:contains("Score")').closest('tr').hide();
});

-------------------
</script> 

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$('select[title=ColumnName]').val('ValueYouWant');
$("nobr:contains('ColumnName')").parent('h3').parent('td').parent('tr').hide();
});
</script> 


 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$('select[title=ColumnName]').val('ValueYouWant');
$("nobr:contains('ColumnName')").parent('h3').parent('td').parent('tr').hide();
});
</script>


-----------------------
http://www.sharepointdiary.com/2012/12/hide-columns-in-newform-editform-dispforms.html

Using SharePoint Manager Tool to Hide SharePoint List Form Fields:
My favorite utility, SharePoint Manager is not just a Object Explorer but supports changing configurations also. So we can use SharePoint Manager to change the specific fields properties. Just download the SharePoint Manager, navigate to the field all the way through Web Applications, Site Collections, Sites, Lists. Set the "ShowInDisplayForm" or whatever required and save the changes.


PowerShell Script to Hide SharePoint List Columns:
SharePoint fields can be hidden programmatically. Why not PowerShell? Lets use PowerShell to set the field properties.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get the Web
$SPWeb = Get-SPWeb "http://sharepoint.crescent.com"
#Get the List
$SPList = $SPWeb.Lists["Project Matrics"]
#Get the Field
$SPField = $SPList.Fields["Parent Project"] 

#Hide from NewForm & EditForm
$SPField.ShowInEditForm = $true
$SPField.ShowInNewForm  = $false

$SPField.Update()
$SPWeb.Dispose()

Same code goes in MOSS 2007 also, with slight change to hide list field in SharePoint 2007:
 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

  $SPSite = New-Object Microsoft.SharePoint.SPSite("http://sharepoint.crescent.com")
  $SPWeb = $SPSite.OpenWeb()

  $SPList = $SPWeb.Lists["Project Matrics"]

  $SPField = $SPList.Fields["Parent Project"]
  $SPField.ShowInNewForm = $False
  $SPField.ShowInEditForm = $False
  $SPField.Update()

  $SPSite.Dispose()

Object Model C# Code to hide fields on a form:
       using (SPSite oSPSite = new SPSite("http://sharepoint.crescent.com"))
            {
                using (SPWeb oSPWeb = oSPSite.OpenWeb())
                {
                     //Get List & Field
                    SPList oSPList = oSPWeb.Lists["Project Metrics"];
                    SPField oSPField = oSPList.Fields["Parent Project"];

                    oSPField.ShowInEditForm = true;
                    oSPField.ShowInNewForm  = true;

                    oSPField.Update();

                }
            }

 Before hide column from SharePoint list: Parent Project

Using JavaScript to Hide Form Fields:
Just edit the List form page by appending ?toolpaneview=2 at the end. Add a CEWP to the page, place this JavaScript code: (Its not written by me, BTW!)
<script language="javascript" type="text/javascript">
_spBodyOnLoadFunctionNames.push("HideColumns");

function GetControl(FieldName) 
{
   var arr = document.getElementsByTagName("!");

   for (var i=0;i < arr.length; i++ )
   {
      if (arr[i].innerHTML.indexOf(FieldName) > 0) {
          return arr[i];     
      }
   }
}

function HideColumns()
{
   var control = GetControl("Parent Project");
   control.parentNode.parentNode.style.display="none";
}
</script>