Tuesday 2 April 2013

List Fields not showing up in Edit, Display or New Forms when we create a new List Definition on Sharepoint 2010

Create List Definitions, suppose to be an easy task to do, but sometimes you could end wasting plenty of time. How do you avoid that?. Well one of the most common errors is that after creating the list you are going to add your new item, and by magic the fields are not populated in the entry form. You go to your view, and you see they are all there.

This happens because the content type created by Visual Studio keeps pointing to the default one, 0x01. How to sort it?, pretty easy:

Step 1
Go to Schema.XML and find the section content types, it should look something like this:

 <MetaData>
    <ContentTypes>
      <ContentTypeRef ID="0x01">
        <Folder TargetName="Item" />
      </ContentTypeRef>
      <ContentTypeRef ID="0x0120" />
    </ContentTypes>
    <Fields>


Step 2
Now, just remove that annoying default content type. The whole new thing should look like this:

  <MetaData>
    
    <Fields>


Step 3
If you want to be 100% sure that you want to display the form properly, just add the following attributes to the element field: 
- ShowInEditForm = “TRUE”
- ShowInDisplayForm = “TRUE”
- ShowInNewForm =”TRUE”


So you should have something like this:

<MetaData>    
    <Fields>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B81}" Name="Manufacturer" DisplayName="Manufacturer" Type="Text" Required="TRUE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B82}" Name="Model" DisplayName="Model" Type="Text" Required="TRUE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B83}" Name="CPUMake" DisplayName="CPU Make" Type="Choice" Required="TRUE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE" >

Conclusion: List definition, are cleaner that programmatically modes, but you could end having big headaches if they don’t work properly.

No comments: