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!
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.
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.
You can do both. In this case I was using the default form.
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.
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?
hmmm..is the page giving you errors?
Try putting it on top of the page ?
Very nice solution.. it works.. thanks for sharing.. 😉
It is working fine..
At the end close the function with );
Like below
$(document).ready(function() {
$("select[id*='ContentTypeChoice']").closest('tr').hide();
} );
You are right!! totally forgot the extra ); there !!
Fixed it.
Thanks this worked great. I'm using a CEWP linked to a js file.
Worked great! Life saver
Works like a charm!
Thanx a lot