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

原文链接:http://www.katriendg.com/aboutdotnet/2007_2_12_publishing_content_types_required_fields.aspx

 

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.

posted on 2008-10-11 19:38  王丹小筑  阅读(269)  评论(0)    收藏  举报

导航