Hide Columns in SharePoint New, Edit and Disp Forms

Hiding columns in SharePoint is nothing new really, there have been several articles written on this topic. The approach for doing this, however, does inspire some debate in terms of what the best practice is. Let’s say we can agree that there are three ways to get this done:

  1. Using the built in content types to specify which columns you wish to be hidden.
  2. Using jQuery and a content editor web part to hide the columns as desired.
  3. Hide the columns programmatically using code.

I just wanted to make some comments on all three. The content type approach is a good one and relatively simple to implement. Once you’ve enabled content types for your list or library, click on the default content type, let’s say it’s Item, and choose the column you’d like to have hidden and simply set it’s column settings to Hidden. Here is an excellent reference for this technique: http://littletalk.wordpress.com/2009/03/30/hide-remove-title-column-from-sharepoint-list/.

Ok so the above works good, but what happens if you only want to introduce these hidden columns on your New and Edit forms but not your Disp form as an example. Or what if your scenario requires that they are hidden from all default New, Edit and Disp forms, but you have some custom SharePoint Designer disp forms that you’ve created that those fields need to be visible on. The content type approach will hide the column for all forms and so that won’t always work. We need something more granular.

So there is where the jQuery approach comes in handy. Some great resources for this:

As per the comments by Nathan Ahlstrom in the second link noted above, the final fix for me was to use:

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

Please note that I had to add quotes around the tr tag for this to work for me.

The final approach uses some custom code and the object model to hide columns for a given list. http://www.sharepointkings.com/2008/05/how-to-hide-column-of-sharepoint-list.html. Now I’m not entirely sure how this works with custom forms besides the New, Edit and Disp forms, and until I have time to try out, I won’t know the answer to that. It’s worth mentioning because it does give you some granularity in that you can specify hidden properties per form.

That’s all for now. Please send in your comments if you have them, would love to hear from you.

,

28 Responses to “Hide Columns in SharePoint New, Edit and Disp Forms”

  1. Ani May 29, 2011 at 10:17 am #

    Great post! I was looking for something like this…thanks

  2. Etienne July 26, 2011 at 1:45 am #

    Where must this code be placed on NewForm.aspx, like under what tags?
    Will this work in SharePoint 2010?

  3. shereen July 26, 2011 at 5:47 pm #

    Hi Etienne,

    I’m working on a follow up post right now that will describe this in more detail. This will work with 2010 but there is a better way, I’ll document that as well.

  4. Etienne August 22, 2011 at 4:22 am #

    Any luck with this Shereen?

  5. shereen August 29, 2011 at 9:53 am #

    Hi Etienne,

    Ok so I had thought you were asking something a little different, but now that I read this post again, you’re simply asking where in the NewForm.aspx you need to place your code? For this example, I’ve placed it just above:

    <asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">.

    Can you give that a try and let me know if it works?

  6. Jerry September 21, 2011 at 1:13 pm #

    I have SharePoint 2007. I do not have access to the server, but I am the site owner. I have a field “Priority Justification” in my change request list – but I want that field to be hidden until/unless the priority changes to something higher than “normal.” Any ideas?

  7. shereen September 23, 2011 at 7:57 am #

    Hi Jerry,

    Have you looked up any jQuery solutions that might assist? So do you want to hide the column for just the new, edit and disp forms, or also within the views?

  8. Manjiri December 13, 2011 at 9:37 am #

    By using jQuery, I am able to hide fields in the “new” and “edit” forms. But, the script is not working for the display form. The script is getting executed, but the fields do not get hidden. Any solution here?

  9. shereen December 13, 2011 at 12:20 pm #

    Hi Manjiri,

    Can you send me the source code for the dispform (if that’s permitted)? It’s likely going to be because the way in which we’re attempting to locate the element is not working. In the mean time, I can try to see if this is reproducible on my end. shereen at qumsieh dot ca.

  10. Madhu January 12, 2012 at 11:09 am #

    Hi Shereen,
    I have a custom edit form where I am trying to use jQuery to enabledisable fields based on the current login. Where exactly do I put my jQuery code in my custom form? I use SPD for customization. Appreciate any response.

  11. shereen January 13, 2012 at 5:31 pm #

    Hi Madhu,

    If you are using SharePoint Designer, you have a couple of options:

    1. Using Design view, you can add a content editor web part to the page, and then insert the jQuery code within the content editor.
    2. You can insert the logic directly into the custom editform.aspx page within the PlaceHolderAdditionalPageHead content placeholder. Are you already linking the jQuery library in your master page? If not, you’ll have to include a link to the jQuery library above the script tag as well. Alternatively you could put the javascript in an external file and link to it from within your page. Does that help?

  12. ashik February 6, 2012 at 1:38 am #

    Hi All

    I wanted to hide a meta data called content type in my EditpageForm.aspx.
    I pasted this code in the Content Editor web part.But this is not working how will my jquery get called??

    $(document).ready(function() {
    $(‘nobr:contains(“Content type”)’).closest(‘tr’).hide();
    });

    My requirement is in the link below
    http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/2a15a8b3-bb78-459b-85a6-6412f6398647

  13. shereen February 6, 2012 at 4:43 pm #

    Hi Ashik,

    Do you have jquery included in your page?

  14. ashik February 10, 2012 at 5:03 am #

    shereen nope where should i include that??In the Master Page??Is there no other way apart from addin in master page??

  15. shereen February 10, 2012 at 11:44 am #

    Hi Ashik,

    You bet, you need to include it either in the master page, or directly in the content editor. Here, let me show you an example, so I may have a content editor with the following content:

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

    So in the above example, I’ve copied my jQuery file to: C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATELAYOUTSjavascriptjquery-1.7.1.js. Does that make sense? You can test that you have jQuery successfully loaded by using the Firefox Firebug console and typing something like $(“div”) and seeing if it returns all the divs in the DOM or if it throws an error.

    Let me know if that helps.

  16. Josh Korn October 2, 2012 at 11:18 am #

    Shereen:

    Do you have any idea how to hide columns in Datasheet view (i.e. without specifically constructing a Datasheet View)? There are several SPField flags (e.g. ShowInDisplayForm, ShowInEditForm, ShowInNewForm, ShowInViewForms) that work for everything *except* Datasheet View.

    Regards
    Josh

  17. shereen October 19, 2012 at 11:15 am #

    Hi Josh,

    Good question, I’ve never had to do that I don’t think. Obviously setting the hidden attribute is not what you want. Did you ever find a solution for this?

  18. Staci October 31, 2012 at 5:14 am #

    Any idea how to hide the created by “user Name” in the view and edit forms?

  19. shereen November 2, 2012 at 10:59 am #

    Hi Staci,

    You’d likely need some javascript for that. Do you need some help with how to do it?

  20. tadreu March 5, 2013 at 4:49 am #

    There is one more solution, even simpler than that:
    Inside tag of the column you want to hide, you can add this: style=diplay:”none”. So the tag would look like this:

    That column must be non-required.
    Remember that this happens only in custom forms

  21. shereen March 5, 2013 at 1:14 pm #

    Hi Tadreu,

    As you’d mentioned, your solution only works in custom forms. This post is specifically for out of the box forms, where you want something non-intrusive.

  22. Lars July 5, 2013 at 4:28 am #

    I used to hide columns the same way Shereen, but I think I’ve found a better way: changing the field schema. And you can even do it via JavaScript now in SharePoint 2010.

    Here’s the method and HTML to do it: http://larslynch.blogspot.com.es/2013/07/best-way-to-hide-columns-in-sharepoint.html

  23. Shereen Qumsieh July 17, 2013 at 4:22 am #

    Thanks Lars! This is awesome.

  24. Nitin September 24, 2014 at 6:02 am #

    am developing a help desk where user will raise a request and it goes to the manager and manager assigns the same request to his subordinate and he writes his comments and change the status from open to reviewed and it again goes to user who raises the request …. here when the user goes in edit mode to close the status he should be able to see manager comments and his subordinate comments ,how do i hide fields text during edit mode please let me know

Trackbacks/Pingbacks

  1. Links (2/21/2010) « Steve Pietrek-Everything SharePoint/Silverlight - February 21, 2010

    [...] Hide Columns in SharePoint New, Edit and Disp Forms [...]

  2. SharePoint 2010: Ocultar / des-ocultar campos de formulario de lista (I)! - Blog del CIIN - February 20, 2012

    [...] http://blog.qumsieh.ca/2010/02/16/hide-columns-in-sharepoint-new-edit-and-disp-forms/ [...]

  3. SharePoint 2010: Ocultar / des-ocultar campos de formulario de lista (I)! « Pasión por la tecnología… - February 20, 2012

    [...] http://blog.qumsieh.ca/2010/02/16/hide-columns-in-sharepoint-new-edit-and-disp-forms/ [...]

  4. Leave Request Approval Workflow « The SharePoint Concierge – All things for the SCA - January 21, 2013

    [...] If I were to deploy this in a production environment, I would hide the new item flag (change it to “hidden”).  The new item flag and “workspace” columns should also be hidden, but you’ll need to use JavaScript/jQuery and a content editor web part for this. You can easily find references on how to do this, but here is a link to some sample code:http://blog.qumsieh.ca/2010/02/16/hide-columns-in-sharepoint-new-edit-and-disp-forms/ [...]

Leave a Reply