Custom Edit form for Multiple Content Type in a SharePoint 2013 list

client-side-scriptingcontent-typeformssharepointsharepoint-2013

In one of my recent project I am currently stuck in a situation where I have to create multiple custom edit forms for each content type that the SharePoint list has.

Example, I have a SharePoint document library with 10 content types. One of them a Base content type inheriting from 'Document' and the others inheriting from the 'Base'.

Now, documents will be uploaded to the site using BizTalk and users will only edit the document, selecting appropriate content type, fill up required fields and save. Now, since the documents will be uploaded through BizTalk, we have decided to remove the 'Required' field settings for all columns and only in the custom edit form we will have to validate them.

So far, I was able to create custom edit form and hook up to a list definition. I think, I'll also will be able to create multiple edit forms and hook up with each of the content types in the content types 'Element.xml' file. But, how I can show the 'Content Type' choice field at the top and redirect to appropriate edit form in each page?

I was thinking of creating a select box, loading it with all the available content types in the list and on selected item change event I can redirect to appropriate edit page. But, is this a correct way to do?

With my solution in mind, I have to create 10 custom edit forms and I have to set up all the fields by hand, which is very tedious. Is there any simple way of doing it?

Please note, I have to add custom client side validation also to the edit form based on the content type chosen.

Also, the requirement is to do most of the things in client side. i.e. loading of items, validation, saving to SharePoint etc. I am using Knockout + jQuery for this task.

Thanks in advance.

UBK

Best Answer

If, in Library Settings->Advanced, you allow for 'Management of Content types', the user should be able to use the standard SharePoint generated Edit form to change content types, there is a dropdown at the top.

I would create a new content type that has all fields you need, but none required, for your Biztalk uploads. In your other content types you can leave the required flags where needed.

BTW, in Office365 document libraries you don't have to do the last step, there is an 'Unknown content type' that you can add to the library for this purpose. Not sure that's available on on-prem SP2013 somehow.

Now you only have to add your jQuery magic to one form. Using SharePoint's for has the advantage that it supports all field types, validation rules etc.

Related Topic