1

I have a custom list and I am using content types to add items to the list. I am using OOTB forms for new and edit items. One field that I see on the EditForm.aspx is the one that I hope I get on the NewForm.aspx also and it is the Content Type field. It is shown in the following screenshot. Do you know how to add that field on the NewForm.aspx page also?

EditForm.aspx

Thanks.

1

There is a unique query string parameter on the newform url that tells Sharepoint what form to render. You can put a content type field on a custom html or aspx page, then use web services to submit the item otherwise, you can't get that on the newform.

If you go to the list and use the ribbon to create each content type, you can snatch the URLs and then use those in your presentation logic for the users.

  • So the straight answer is that it is not possible without creating custom form for each content type? I don't undrstand how MSFT can overlook this feature. What's the point of the Content Type field on the EditForm.aspx and not on NewForm.aspx which is after the fact? – Aamir Jan 6 '15 at 19:58
  • Correct. The point of it being on the edit form is so that it can be changed from one content type to another. Laura Rogers has documented many use cases of document lifecycle and workflow by simply changing the content type of document or list item from one to another. It doent make a lot of sense for me to click a link to create Content Type A, then be presented with a dropdown asking me what content type I want it to be after explicitly clicking a link for type A. – Eric Alexander Jan 6 '15 at 20:13
  • Well, it makes sense to me, because after clicking the generic New Item link right above the list view, I have the opportunity to select which content type I need to enter. – Aamir Jan 6 '15 at 20:20
  • Right, you are clicking a link for an explicit content type in that scenario, like TPS report, so why should the form then have an option to specifiy a content type other than TPS report, that makes no sense. – Eric Alexander Jan 6 '15 at 20:24
  • My needs are different. It is a design issue MSFT should address. One should have an option for not to select a default content type. In such a case user should be presented with a content type dropdown box on a NewForm.aspx. – Aamir Jan 6 '15 at 23:31
0

Unless you create your own URL to NewForm.aspx without parameters,
the ContentTypeId is by default present as a QueryString parameter.

So you can add some JavaScript to that single NewForm.aspx (edit in advanced mode) just before the table of the form, that matches by ContentTypeId and prints a header.

If you don't have SharePoint Designer add a ContentEditorWebPart to page.

    <script>
        JSRequest.EnsureSetup();
        var ctID=JSRequest.QueryString['ContentTypeId'];
        var titles={
            '0x0100223....010019ABEA5C55C59D4383F98D5A938894D8' : 'Expense',
            '0x0100223....02006C9B8D0CCE23024EA3A01C9A93FAFBB3' : 'Invoice',
        };
        var title = titles[ctID] || ctID;
        document.write( String.format('<h1 title="{1}">New 365CSI: {0}</h1>', title,ctID ));
    </script>

    <table class="ms-core-tableNoSpace" id="onetIDListForm">

Always get the correct ContentTypeId

After pageload the ContentType info is always present in:

WPQ2FormCtx.ItemContentTypeId
and
WPQ2FormCtx.ItemContentTypeName

But you better make sure you reference the correct WebPart (WPQ2 most of the time)

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.