Publishing Content types and site columns using features - specifying required fields in the XML schema

Today I came across something strange after having created site columns and content types (for publishing) using features.
Two features are used:

  • Site fields/columns definition where I specify the definition of each site column.
  • Content types: based on publishing content types to be used by page layouts. This feature refers to the fields created by my first feature.

My problem was that all required fields defined by my site columns feature were not being validated as required field after saving the page. In other words, the page was saved without error messages being shown for the required fields.
Site column definition specifies the field is required however:

<Field ID="GUID_HERE" Name="MyDateField" StaticName="MyDateField"
SourceID=http://schemas.microsoft.com/sharepoint/v3
Group="My publishing group"DisplayName="MyDateField"
Type="DateTime"
Format="DateTime"
Required="TRUE"
Sealed="TRUE"
StorageTZ="UTC"></Field>

The reason for this behavior: fields being marked as Required="True" in the fields definition feature are not automatically set as required in the content type.

<ContentType ID="ID_HERE" Name="MyContenttype" Group="Mygroup" Sealed="FALSE" Version="0">
<FieldRefs>
<FieldRef ID="{82734328-4682-43a9-A516-96C96FBBEE40}" Name="MyTextField" />
<FieldRef ID="{3843B4BD-CB7C-4339-A499-638501E0E44F}" Name="MyDateField" Required="TRUE" />
</FieldRefs>
<DocumentTemplate TargetName="/_layouts/CreatePage.aspx" />
</ContentType>

In the above sample the first field will not be validated in the page layout, even if this field has been set as required in the <Field> definition file. The second field in the content type, setting Required="TRUE" explicitly will be correctly validated.

If you create your publishing content types directly using the MOSS interface you will probably never run into the problem.
 

Feedback

Posted on 28 October 2008 @ 03:18

Thankyou very much for this information.
I was wondering why the hell all the fields in my provisioned content types were optional (even though many of them were set to required).

It was because I had Required="True" and not Required="TRUE" on the FieldRef in the content type CAML. I had no idea it was case sensitive!!! The XSD that provided intellisense in Visual Studio indicated that casing wasn't important! :(

Well, at least they are all required now. Thanks again.

I still don't understand why just making the field itself required doesn't make it required by default in the content type...

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Copyright © 2007 Katrien De Graeve.