none
How to hide the content type field? RRS feed

  • Question

  • Hi all
        I add some content types to a list. Then when I create a item in this list with one of these content types. On the new page. at the top therer is a drop down, which you can choose the content type. How can I make it read only or hide it? Thanks!
     
    Thursday, February 19, 2009 5:33 AM

Answers

  • Sorry, I misunderstood your requirement

    But,

    Follow the steps to hide field

    1. Open SharePoint Designer and navigate to the site that contains the list or document library you wish to customize.
    2. Expand the folder named “Forms” under the desired list or document library.  You should see about seven .aspx pages (AllItems.aspx, EditForm.aspx, NewForm.aspx, etc)
    3. Open the Form.aspx page and switch to the “code” view to edit the HTML of the page.
    4. Paste the JavaScript code immediately below the the following HTML tag <asp:Content ContentPlaceHolderId=”PlaceHolderMain” runat=”server”>  This will add the JavaScript to the HTML inside the content placeholder tag.  Note: be sure to include the entire script below, including the <script and </script> tags.
    5. Modify the “hidefields()” section of the JavaScript code to refer to each SharePoint list field name to hide.  For example, the code sample below will hide the SharePoint fields named Title, Document Link, and PublishDate    Notice that you do not need to worry about internal field names or field types like other JavaScript techniques, you simply need to know the name of the field.
    6. Save the changes.  Select “Yes” when prompted to “…customize the page from the site definition…”
    7. Test the form

    Javascript:

    <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("Content Type");  
       control.parentNode.parentNode.style.display="none";  
       }  
    </script> 
    • Marked as answer by jdxyw Monday, March 2, 2009 1:08 AM
    Friday, February 20, 2009 12:34 PM

All replies

  • You can hide the content types you do not want to appear on the "new" link.

    Navigate to the "List/Document Library Settings" --> "Advanced Settings" --> Check the "Allow management of content types?" radio button to yes and say "OK"

    Get back to the settings page...now you will be able to see a new section as "Content Types"

    Click on the link "Change new button order and default content type".

    Uncheck the checkboxes for the content types which you do not want to be visible.

    • Proposed as answer by Dhirendra Yadav Thursday, February 19, 2009 8:33 AM
    • Unproposed as answer by jdxyw Friday, February 20, 2009 1:01 AM
    • Proposed as answer by Ravi S Kulkarni Monday, May 30, 2011 8:07 AM
    Thursday, February 19, 2009 8:33 AM
  • DhirenY said:

    You can hide the content types you do not want to appear on the "new" link.

    Navigate to the "List/Document Library Settings" --> "Advanced Settings" --> Check the "Allow management of content types?" radio button to yes and say "OK"

    Get back to the settings page...now you will be able to see a new section as "Content Types"

    Click on the link "Change new button order and default content type".

    Uncheck the checkboxes for the content types which you do not want to be visible.



    Hi Dhireny
        I think you misunderstand my meaning. What my situation is that when I have a item now. Then I edit that item. At the top of that edit page, there is a drop down list field, from this list you can choose the content types that belong to the list. I want to hide this field.
    Friday, February 20, 2009 1:05 AM
  • Set that field as hidden.
     SPField.Hidden = true;
    Friday, February 20, 2009 2:43 AM
  • Zhang Mingquan Mike said:

    Set that field as hidden.
     SPField.Hidden = true;



    No work.
    Friday, February 20, 2009 8:32 AM
  • Sorry, I misunderstood your requirement

    But,

    Follow the steps to hide field

    1. Open SharePoint Designer and navigate to the site that contains the list or document library you wish to customize.
    2. Expand the folder named “Forms” under the desired list or document library.  You should see about seven .aspx pages (AllItems.aspx, EditForm.aspx, NewForm.aspx, etc)
    3. Open the Form.aspx page and switch to the “code” view to edit the HTML of the page.
    4. Paste the JavaScript code immediately below the the following HTML tag <asp:Content ContentPlaceHolderId=”PlaceHolderMain” runat=”server”>  This will add the JavaScript to the HTML inside the content placeholder tag.  Note: be sure to include the entire script below, including the <script and </script> tags.
    5. Modify the “hidefields()” section of the JavaScript code to refer to each SharePoint list field name to hide.  For example, the code sample below will hide the SharePoint fields named Title, Document Link, and PublishDate    Notice that you do not need to worry about internal field names or field types like other JavaScript techniques, you simply need to know the name of the field.
    6. Save the changes.  Select “Yes” when prompted to “…customize the page from the site definition…”
    7. Test the form

    Javascript:

    <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("Content Type");  
       control.parentNode.parentNode.style.display="none";  
       }  
    </script> 
    • Marked as answer by jdxyw Monday, March 2, 2009 1:08 AM
    Friday, February 20, 2009 12:34 PM
  • hi yadav,

    I got same problem.I got followed above process using Content editor web part.But still its displaying me the content type drown down.can you suggest on this.


    Thanks & Regards, Krishna

    Monday, May 14, 2012 12:02 PM