views:

866

answers:

3

I've written a schema for a list that only needs to add one column to the default custom list which is a number field called months. The field is shown on the default view and is indeed created on the list. The list is autopopulated with values which get set properly. The problem is that the field doesn't appear on the display/edit/new pages. It can be set through the datasheet view. I don't understand why it isn't showing up when I specifically set it to in the schema.

Would very much appriciate any suggestions.

<?xml version="1.0" encoding="utf-8"?>
<List xmlns:ows="Microsoft SharePoint" 
      Title="ReviewPeriods" 
      FolderCreation="FALSE" 
      Direction="$Resources:Direction;" 
      Url="Lists/ReviewPeriods" 
      EnableContentTypes="TRUE" 
      BaseType="0">
 <MetaData>
  <ContentTypes>
   <ContentTypeRef ID="0x01">
        <Folder TargetName="Item" />
      </ContentTypeRef>
  </ContentTypes>
  <Fields>
   <Field ID="{B99EB797-4057-4a75-90BF-B40D0F89A9D9}"
             Type="Number"
             Decimals="0"
             Min="0"
             Max="100"
             Percentage="FALSE"
             Name="Months" 
             Required="TRUE"
             Group="SEED"
             DisplayName="Months"
             StaticName="Months"
             ShowInDisplayForm="TRUE"
             ShowInEditForm="TRUE"
             ShowInNewForm="TRUE">
   </Field>
  </Fields>
  <Views>   
   <View BaseViewID="0" 
            Type="HTML"
            WebPartZoneID="Main" 
            DisplayName="Default View" 
            DefaultView="TRUE" 
            SetupPath="pages\viewpage.aspx" 
            ImageUrl="/_layouts/images/generic.png" 
            Url="AllItems.aspx">

... Hidden Stuff ...

<ViewFields>
          <FieldRef Name="LinkTitle"></FieldRef>
          <FieldRef Name="Months"></FieldRef>
    </ViewFields>
    <Query>
     <OrderBy>
      <FieldRef Name="Title">
      </FieldRef>
     </OrderBy>
    </Query>
   </View>
  </Views>
  <Forms>
   <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
   <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
   <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
  </Forms>
 </MetaData>
</List>
+1  A: 

I've sort of found the solution to my own problem. The field doesn't get listed in the New/Display/Edit forms because those pages are based on the content type. In this case the Item content type that I base my list on.

Usually I create my own content type but I've been trying to find a shorthand way to create a list without defining a whole new content type. So what I've done is define the field directly inside the list schema rather than reference an already existing field that's within the content type. It does seem a little silly to define a content type just for a single use lookup list with only one extra field.

If someone can suggest a way to get the fields to show on the New/Display/Edit forms without having to create a new content type then I will happily make them the accepted answer instead.

Dan Revell
+3  A: 

The problem is that you add the field to the list, but at the same time enable content types and specify that the only content type to use is Item (0x01) which doesn't include the field. So you're adding/editing Items and then you don't get the field.

There are two solutions:

  1. Don't enable content types (and then also remove the whole <ContentTypes> section)
  2. Create a new content type including the field and add that content type instead of Item
Per Jakobsen
I've already gone for the second solution you list although I am interested in the first. Is it actually possible to outright disable content types on a list or is it just getting hidden away.
Dan Revell
If you just leave out the EnableContentTypes attribure and the <ContentTypes> section then you'll get a list where the added fields show up on add/edit of Item
Per Jakobsen
+1  A: 

As you did I was doing the same thing (Creating Content Type for each of the List I wanted to create) Until I hit the below code. If you look at the below code I have removed the <ContentTypes> tag and forcibly added the Title Field and the extra field Description.

<Fields>
  <Field ID="{9830F5FC-99E0-4052-9CC0-50CBEDE80002}" Type="Text" Name="Title" DisplayName="Type Name" Required="TRUE" MaxLength="255" Version="1" RowOrdinal="0">
    <Default/>
  </Field>      
  <Field Type="Note" DisplayName="Description" Required="FALSE" NumLines="6" RichText="TRUE" RichTextMode="Compatible" Sortable="FALSE" 
         ID="{63C25492-BA98-4096-A6D7-F85885E0A425}" Name="Description"
          RowOrdinal="0"/>
</Fields>

......Hidden

<MetaData>

Per Answer was Right +1

Kusek