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

2

You can use SPField.ShowInEditForm and SPField.ShowInNewForm

Show Hide columns using PowerShell

  • 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 Gu Feb 1 '18 at 17:33
  • Yes it should work the same way – Arsalan Adam Khatri Feb 4 '18 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

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.

  • 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 Gu Feb 1 '18 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 Feb 3 '18 at 13:41
  • I don't use JSRequest, but in vanilla JS queryString refers to everything after the '?'... – Ken Hansen Feb 5 '18 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 Feb 5 '18 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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