SharePoint online or SharePoint 2013 hide content type in Edit Form using jQuery

sharepoint 2013 hide content type in edit form

Here we will discuss how we can hide the content type drop-down which comes in edit form inside SharePoint online task list. The same solution will also work for SharePoint 2013 and SharePoint 2016.

Recently we were working in a visual studio 2015 workflow, there we have added the various custom content types into the task list. If you are new to visual studio workflow, you can check out below article:

SharePoint deveopment training course

– Step by step develop workflows using visual studio 2015 as an add-in and deploy to host web in SharePoint online?

By default whenever a task got created and a user wants to approve/reject the task from the edit form, the content type drop-down appears like below:

SharePoint online hide content type in task list edit form
SharePoint online hide content type in task list edit form

As per the requirement, we need to hide the content type drop down from the task list edit form.



Solution:
We can hide the content type by using below jQuery code.

Either we can put the code inside the Edit form task list or we can also put inside master page.

To put inside the page, Edit the page -> And then add a script editor web part. Inside the script editor web part put the below code. Once you Save the page and refresh it will hide the dropdown.

<script language=”javascript” type=”text/javascript” src=”https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js”></script>
<script language=”javascript” type=”text/javascript”>

$(document).ready(function () {

$(“select[id*=’ContentTypeChoice’]”).closest(‘tr’).hide();

});

</script>

Similarly we can put the code inside a master page. But since when you put the code inside master page, it might hide every list, so I had added one condition like below:

– First retrieve the browser URL like : var pageURL = $(location).attr(“href”);
– Then if the URL contains the list URL then only it will hide.
if( pageURL.indexOf(‘/WorkflowTasks/’) >= 0)
{
}

The full code like below:

<script language=”javascript” type=”text/javascript” src=”https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js”></script>
<script language=”javascript” type=”text/javascript”>

$(document).ready(function () {
var pageURL = $(location).attr(“href”);

if( pageURL.indexOf(‘/WorkflowTasks/’) >= 0){

$(“select[id*=’ContentTypeChoice’]”).closest(‘tr’).hide();
}

});

</script>

Once you put the above code inside the master page, it will hide the content type.


Read some SharePoint online tutorials:

sharepoint 2013 hide content type in edit form
sharepoint 2013 hide content type in edit form

Hope it will be helpful.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bhawana Rathore

Hello Everyone!! I am Bhawana a SharePoint MVP and having about 8+ years of SharePoint experience as well as in .Net technologies . I have worked in all the versions of SharePoint from wss to Office 365. I have good exposure in Customization and Migration using Nintex, Metalogix tools . Now exploring more in SharePoint 2016 :) Hope here I can contribute and share my knowledge to the fullest. As I believe "There is no wealth like knowledge, and no poverty like ignorance"

View all posts by Bhawana Rathore →