Hide the Content Type field in the editform via jQuery

Hi again,
Another blogpost here about jQuery.
After my blogpost about hiding fields in the Editform, I got a lot of questions on how to hide the Content Type field. For instance, when you create a folder content type, you will always have the choice to select the default content type “folder”.
So let us check out what happens in SharePoint and how you can use jQuery to hide the content type field.

Editform
SharePoint output:

<tr>
   <td nowrap="true" valign="top" class="ms-formlabel">Content Type</td>
   <td valign="top" class="ms-formbody">
     <select name="ContentTypeChoiceCode" id="ContentTypeChoiceID" title="Content Type">                                  <option selected="selected" value="ContentTypeID1">Content Type1< /option>                                 
<option value="ContentTypeID2">Content Type2< /option>
     </select>
  <br/>
  <span id="ContentTypeDescription">< /span>
 </td>
</tr>

Code
Contrary to the other fields, we have no NOBR tag here. We do have a formlabel and a select field.
So instead of referencing to a field, we will reference to the id of the select field. That id contains a big id number, but also the text “ContentTypeChoice”.

$(document).ready(function() {
         $("select[id*='ContentTypeChoice']").closest('tr').hide();
});

Don’t forget to reference to the Jquery file!

About: Marijn

Marijn Somers (MVP) has over 14 years experience in the SharePoint world, starting out with SP2007. Over the years the focus has grown to Office 365, with a focus on collaboration and document management. He is a business consultant at Balestra and Principal Content Provider for "Mijn 365 Coach" that offers dutch employee video training. His main work tracks are around user adoption, training and coaching and governance. He is also not afraid to dig deeper in the technicalities with PowerShell, adaptive cards or custom formatting in lists and libraries. You can listen to him on the biweekly "Office 365 Distilled" podcast.


12 thoughts on “Hide the Content Type field in the editform via jQuery”

  1. Hi,
    Are you running that jQuery inside of a custom edit form? or is just the default form?

    In the latter case, how do you manage to run your jQuery?

    Thanks.

  2. Hi,
    Are you running the jQuery code inside of a custom edit form or are you using the default form for folder that SharePoint provides?

    In the latter case, how do you manage to call jQuery code?

    Thanks.

  3. Hi,

    > In the latter case, how do you manage to call jQuery code?
    If you just need it in one particular edit form, I would suggest:
    Use a content editor webpart and add the js code as content.
    If you use it on all editforms in your web a dedicated webpart or delegate control that adds the js code would do it.

  4. Hi, great post!
    But it is not working for me. I put this code just after
    in my EditForm.aspx

    I added the reference for the JQery file that is stored on my server correctly.

    Am I missing something?

  5. It is working fine..
    At the end close the function with );

    Like below

    $(document).ready(function() {
    $("select[id*='ContentTypeChoice']").closest('tr').hide();
    } );

Leave a Reply

Your email address will not be published. Required fields are marked *