1

I have the following inside my SharePoint 2013 on-premises.

  1. Custom List inside my Team site.
  2. Three Content Types inside the Custom List.

Now when i create a new item by clicking on the "new item" link :-

enter image description here

i will only get the fields for the defualt content type. while if i edit an existing item, i will get the "Content Type" drop-down list:-

enter image description here

so my questions are how i can do the following/if possible:-

  1. Hide the "Content type" drop-down list from Edit form.
  2. Show the "Content type" drop-down list inside the New form.

Thanks

4 Answers 4

2

You can use SPField.ShowInEditForm and SPField.ShowInNewForm

Show Hide columns using PowerShell

2
  • will this also apply to the "Content Type" system generated column ? as the "content type" dropdown list is not part of the list or the site columns.
    – John John
    Commented Feb 1, 2018 at 17:33
  • Yes it should work the same way Commented Feb 4, 2018 at 13:00
2

To hide the "Content type" drop-down list from Edit form, add a content editor web part in the Edit form, add the following code in it:

<script src="http://code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script> 
<script type="text/javascript">
$(function() {
  $("select[id*='ContentTypeChoice']").closest('tr').hide(); 
}); 
</script>

As for show the "Content type" drop-down list inside the New form, unless you create your own URL to NewForm.aspx without parameters,the ContentTypeId is by default present as a QueryString parameter.

Each content type has its own newForm.aspx. When added to a list you choose which content type (which newForm.aspx) you want to use on the dropdown of the new button. By the time you get to the newForm.aspx you are already committed to a specific content type.

Here is an similar issue post for your reference:

Content Type field on NewForm.aspx

0
0

The simplest option is to use the New Item drop-down in the Ribbon...

Ribbon Drop Down

For a new item, SharePoint determines the form to use based on a QueryString parameter that includes ContentTypeId. This prevents on the fly changes to the form once it is opened... See this question for more detail.

You could create a custom form to handle this situation (Nintex or something would really help here) but you would have to decide if it's worth the time.

4
  • now i try to get the content type id from the query string as follow JSRequest.EnsureSetup(); var ctID=JSRequest.QueryString['ContentTypeId']; alert(ctID); i added this script inside a script editor inside my New form .but the above will return undefined..
    – John John
    Commented Feb 1, 2018 at 21:53
  • Can you see it in the url itself? I would look at a way to override the behavior of the new item button, and give it a poop up menu... I might try this next week and will post what I come up with.
    – Ken Hansen
    Commented Feb 3, 2018 at 13:41
  • I don't use JSRequest, but in vanilla JS queryString refers to everything after the '?'...
    – Ken Hansen
    Commented Feb 5, 2018 at 15:15
  • If you just use the new item button it will use the default content type for the list, and will not have the ContentType parameter. Getting the ContentType parameter isn't much help anyway. You want to set it... You might try opening the various forms from the ribbon, check out the URL differences. You could possibly create a new default form with a selector that would open the correct url when selected... In the end, I would find it simpler to teach people to use the ribbon. (Or if necessary I would create a custom form that posts via REST and skip the default view).
    – Ken Hansen
    Commented Feb 5, 2018 at 15:31
0

If you want to hide drop down menu with content type, You can create custom control template for your list.

  1. Add new control template to folder C:\Program Files\Common Files\microsoft shared\Web Server Extensions{current_version}\TEMPLATE\CONTROLTEMPLATES You can take default template from DefaultTemplates.ascx Template for list:
     <SharePoint:RenderingTemplate id="ListForm" runat="server">
        <Template>
            <table>
                <tr>
                    <td>
                        <span id='part1'>
                            <SharePoint:InformationBar runat="server"/>
                            <div id="listFormToolBarTop">
                            <wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTbltop" RightButtonSeparator="&amp;#160;" runat="server">
                                    <Template_RightButtons>
                                        <SharePoint:NextPageButton runat="server"/>
                                        <SharePoint:SaveButton runat="server"/>
                                        <SharePoint:GoBackButton runat="server"/>
                                    </Template_RightButtons>
                            </wssuc:ToolBar>
                            </div>
                            <SharePoint:FormToolBar runat="server"/>
                            <SharePoint:ItemValidationFailedMessage runat="server"/>
                            <table class="ms-formtable" style="margin-top: 8px;" border="0" cellpadding="0" cellspacing="0" width="100%">
                            <SharePoint:ChangeContentType runat="server"/>
                            <SharePoint:FolderFormFields runat="server"/>
                            <SharePoint:ListFieldIterator runat="server"/>
                            <SharePoint:ApprovalStatus runat="server"/>
                            <SharePoint:FormComponent TemplateName="AttachmentRows" ComponentRequiresPostback="false" runat="server"/>
                            </table>
                            <table cellpadding="0" cellspacing="0" width="100%" style="padding-top: 7px"><tr><td width="100%">
                            <SharePoint:ItemHiddenVersion runat="server"/>
                            <SharePoint:ParentInformationField runat="server"/>
                            <SharePoint:InitContentType runat="server"/>
                            <wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTbl" RightButtonSeparator="&amp;#160;" runat="server">
                                    <Template_Buttons>
                                        <SharePoint:CreatedModifiedInfo runat="server"/>
                                    </Template_Buttons>
                                    <Template_RightButtons>
                                        <SharePoint:SaveButton runat="server"/>
                                        <SharePoint:GoBackButton runat="server"/>
                                    </Template_RightButtons>
                            </wssuc:ToolBar>
                            </td></tr></table>
                        </span>
                    </td>
                    <td valign="top">
                        <SharePoint:DelegateControl runat="server" ControlId="RelatedItemsPlaceHolder"/>
                    </td>
                </tr>
            </table>
            <SharePoint:AttachmentUpload runat="server"/>
        </Template>
    </SharePoint:RenderingTemplate>
  1. Delete from control template line with text: <SharePoint:ChangeContentType runat="server"/>

  2. Add this template to your list use powershell

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.