There are many
good reasons to use Content Types… if you can get people to use them, and then
leave them alone. :-)
When creating a
new list item based on a Content Type the user needs to select the Content Type
from the New dropdown. Once selected, the Content Type should generally not be
changed. Changing it is too easy as the user is offered the choice every time they
edit the item.
Preventing this
is pretty easy as all we need to do is hide the first row of the edit form's
HTML table. The following JavaScript will do this for us and will work in both
SharePoint 2007, SharePoint 2010 and SharePoint Online / Office 365:
<script>
var ttnTables =
document.getElementsByTagName("TABLE")
for (var
i=0;i<ttnTables.length;i++)
{
if (ttnTables[i].className=="ms-formtable")
{
ttnTables[i].rows[0].style.display="none";
}
}
</script>
Now the Content
Type is hidden on the edit form.
But Site Owner
Can Change it?
The only
problem with this solution is that it also prevents the site owner from
changing the Content Types. We need to only run the above code for non site
owners. To do this we will use the SPSecurityTrimmedControl and set the
PermissionString to a suitable value, such as ManageWeb.
<!-- default value -->
<script
type="text/javascript">
var canChangeContentType = false;
</script>
<Sharepoint:SPSecurityTrimmedControl
runat="server" PermissionsString="ManageWeb">
<!--text for users who have the ManageWeb permission -->
<script type="text/javascript">
canChangeContentType = true;
</script>
</SharePoint:SPSecurityTrimmedControl>
<script
type="text/javascript">
if (canChangeContentType == false)
{
var ttnTables = document.getElementsByTagName("TABLE")
for (var i=0;i<ttnTables.length;i++)
{
if (ttnTables[i].className=="ms-formtable")
{
ttnTables[i].rows[0].style.display="none";
}
}
}
</script>
There is Work around
A user with
permissions to create private views can create a DataSheet view with the
Content Type column displayed and then edit the Content Type.
Where to Add
this Code
SharePoint
2013
1.
Open SharePoint Designer and open
the site with the list that uses Content Types
2.
In the Folder List pane expand Lists
and your list
3.
Double-click EditForm.aspx
4.
If the HTML is not displayed, click
the Code button at the bottom of the page
5.
Search for
"PlaceHolderMain"
6.
Select the entire line, right-click
the line and select Find Matching Tag (this should find </asp:Content>)
7.
Add the JavaScript from above just
before the </asp:Content> line
8.
Save and test (remember, as a Site
Owner you will always be able to see the Content Type)
SharePoint
2010
1.
Open SharePoint Designer and open
the site with the list that uses Content Types
2.
In the Navigation Pane click Lists
and Libraries
3.
Click the name of the list that uses
Content Types
4.
In the Forms area click
EditForm.aspx
5.
If the window is split into Design
and Code views, click the Split button at the bottom of the window
6.
Click in the area just below the
existing web part
7.
You should see something similar to
the following in the Code view:
8.
Paste the JavaScript from above
between the DIV tags
9.
Save and test (remember, as a Site
Owner you will always be able to see the Content Type)