0

I need some help here. Im customizing forms that have list built using Content Types. I noticed the difference in the links is something like this below I have one default content list type called item and the other one is called College Form

Item is ContentTypeId=0x01003FF12EB7EAB88340BEE53D34C38A906200147E508F34B9164ABE555FF698569C27

College Form is ContentTypeId=0x01003FF12EB7EAB88340BEE53D34C38A906200147E508F34B9164ABE555FF698569C27

When doing my customization of the form I would like to hide some fields and show some based on the content type. I know by default the content type does that. But im using JS to hide some fields but don't know how i can do this or what values to use to make this happen.

Any ideas

1
  • What version of SharePoint are you using? Commented Feb 5, 2015 at 7:17

1 Answer 1

1

WPQ2FormCtx.ItemContentTypeId will give the content type ID of the item in each of the forms newform.aspx, ediform.aspx and displayform.aspx. You can also use WPQ2FormCtx.ItemContentTypeName, if you want to compare name instead of Id. Here is a JQuery code to hide fields in the forms:

<script type="text/javascript">
jQuery(document).ready(function($) {
    if(WPQ2FormCtx.ItemContentTypeId == '0x010400C36D463A4788AD4AAF5F85C02DA29F8E') {
    $("h3.ms-standardheader:contains('Body')").closest("tr").hide();
}
});
</script>

Note that this script assumes the JQuery is already referenced in the site. You can place above code in Script Editor web part in each of the forms. Also, beware that this way you can hide the field from UI, but user can still open the page source and find the actual information in the hidden field. If the requirement is to completely hide the field data then you will need to set the field properties like showInEditForm, showInDisplayForm and showInNewForm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.