Hide Columns in SharePoint List NewForm, EditForm and DispForms
Had a requirement to hide a specific column “Parent Project” in a SharePoint list “Project Metrics”, Since this field was being updated by an internal workflow, it must not be visible in NewForm or in EditForm.
So to protect a particular column from edits, decided to hide it from New & Display Forms. Here are the various methods I’ve used in different scenarios.
SharePoint SPField Object has the following properties to control its visibility.
- ShowInNewForm – Show in the list settings page
- ShowInEditForm – Controls field in edit form page
- ShowInDisplayForm –Show in the display form page.
- ShowInListSettings – Show in the list settings page
- ShowInViewForms –Show field in views field selection
- ShowInVersionHistory – Show in the version history view
These field properties are self-explaining, isn’t it? Let’s see various ways to Hide SharePoint List Columns.
Option 1: Enable Content Type and Hide the Field
This will hide the field from All list forms – NewForm, EditForm and DispForm.
- Go to List Settings and enable content type by clicking “Advanced settings” and then choose “Yes” for “Allow management of content types?”.
- Once done, You see “Content Types” in list settings. Click on “Item” link.
- Select the Field to hide
- Choose “Hidden” under column settings.
This will hide the selected field from ALL List forms (NewForm, EditForm and DispForms).
Option 2: Using SharePoint Manager Tool to Hide SharePoint List Form Fields:
My favorite utility, SharePoint Manager is not just an Object Explorer but supports changing configurations also. So we can use SharePoint Manager to change the specific field’s 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.
Option 3: PowerShell Script to Hide SharePoint List Columns
SharePoint fields can be hidden programmatically. Why not PowerShell? Let’s use PowerShell to set the field properties.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get the Web
$SPWeb = Get-SPWeb "https://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("https://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("https://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
After hiding column from list form page:
Option 4: 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:
<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>
Hide SharePoint list column with jQuery:
This can be done using jQuery as well. Here is my post on How to hide SharePoint list form field using jQuery?
Another alternate would be editing the Form page in SharePoint designer and set “Hidden” property for a relevant field, or even conditional format to hide a filed also will work.
There is a project in Codeplex: Office Toolbox, provides interface for hiding SharePoint list columns/fields from interface. Check it out!
thank you for explaining the ways to hide fields so clearly and step by step. It worked for me! I used the first method.
Hi, This is exactly what I am looking. However, I am looking to hide multiple fields. Could you please let me how can I acheive this?
The content type method would let you hide as many fields as you wanted. Just select each field and set each one to hidden
Hi,
I used above code to hide a peoplepicker in SP 2013. but i found one issue.
if people picker is not having value, it works fine. but if it contains a value, it gives me java script error says “Invalid Argument” clientpeoplepicker.js
Could you please help me to resolve this
To hide / disable People picker fields, use the code in my another post: Disable People Picker, Lookup Fields in SharePoint List Forms