1

I have a list containing different content types.

When I edit an item on the list, I get a dropdown listing all those content types so I can switch it if needed.

Is it possible to have the content type shown on the view form too?

I want the view form to look something like:

Content Type : CType One
Title: Your Title Here
SomeField1: SomeField1 value here
...

Note: I have the restriction of not using SP Designer

2 Answers 2

2

I'm actually fairly sure this isn't possible -- and the reason might seem kind of silly, but is a limitation of the architecture having to deal with content types:

Forms (edit/view) are associated with a particular content type; so when you go to a list and edit an item, the first question SharePoint asks before it renders any form is 'what content type is this' then it asks 'what is the right form for this content type' then it goes and finds that form and renders it.

If you were able to change the content type while editting the form, you wouldn't be in a valid edit state for that item while you were viewing the form that was rendered for the previous content type (since different types can have different fields and other associated metadata)... SharePoint would need to provide a new form for that item based on its new content type.

So that may not be the answer you're looking for, but should shed some more light on the scenario. Also worth noting, InfoPath won't work for you here since it doesn't expose the Content Type field and follows the same Content Type dependency logic I've described above.

If you wanted to design your own way to edit the content type you actually probably could, but you would need to implement something custom using HTML/CSS/JavaScript that could be inserted onto the form edit page in a content editor or something similar (since you can't use designer)

0

I figured it out. Had to use JavaScript for this.

I was able to grab the current item's content type by looking at the ID parameter, grabbing the item based off that and getting its content type.

function queryString(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^&#]*)"),n=t.exec(location.search);return n===null?"":decodeURIComponent(n[1].replace(/\+/g," "))}

function ReadListItem() {
  var listTitle = "List Three"; //<-- Your list name here
  context = SP.ClientContext.get_current();
  var list = context.get_web().get_lists().getByTitle(listTitle);  
  this.listItem =  list.getItemById(queryString("ID"));
  context.load(listItem);
  this.contentType = listItem.get_contentType();
  context.load(contentType);
  context.executeQueryAsync(Function.createDelegate(this, ReadListItemSucceeded), Function.createDelegate(this, ReadListItemFailed));
}

function ReadListItemSucceeded(sender, args) {
  console.log(this.listItem.get_contentType().get_name());
}

function ReadListItemFailed(sender, args) {
  console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

ExecuteOrDelayUntilScriptLoaded(ReadListItem, "sp.js");

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.