In this SharePoint customization tutorial, we will discuss, how to hide the content type drop-down which comes in edit form inside SharePoint online task list. In the same way, we can hide content type field in edit form in SharePoint 2016 or SharePoint 2013.
Recently we were working in a visual studio 2015 workflow, where we have added the various custom content types into the task list in SharePoint.
If you are new to SharePoint visual studio workflow, you can check out Develop SharePoint workflows using visual studio as SharePoint hosted App.
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:
As per the requirement, we need to hide the content type drop-down from the task list edit form.
SharePoint hide content type field edit form
We can hide the content type by using below jQuery code in SharePoint list form.
Either we can put the code inside the Edit form task list or we can also put it inside master page in SharePoint.
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 in the edit form in SharePoint.
You may like following content type tutorials:
- How to get all content types using csom in SharePoint
- Content type Examples using CSOM in SharePoint
- Delete content type from SharePoint list using PowerShell
- Change content type recursively using PowerShell SharePoint 2013
- Report Data Source content type is missing in SharePoint 2013/2016
- Content type HUB SharePoint 2013 Tutorial
- Create Site Column and Content Type using PowerShell in SharePoint 2013/2016
- Another site or list is still using this content type error while deleting content type from SharePoint online site
In this tutorial, we saw how to hide the content type drop-down which comes in edit form inside SharePoint Online/2013/2016 task list.
Bhawana Rathore is a Microsoft MVP (3 times in Office Apps & Services) and a passionate SharePoint Consultant, having around 10 years of IT experience in the industry, as well as in .Net technologies. She likes to share her technical expertise in EnjoySharePoint.com and SPGuides.com
[…] Hide content type field in edit form in SharePoint Online/2013/2016 […]