PANVEGA’s Blog

DotNet Development, SharePoint Customizing, Silverlight, MS Infrastructure and other tips and tricks

Display choices using checkboxes in Field Types (multiple selections)

Posted by PANVEGA on October 1, 2008

For Choice fields, this attribute can be set to Dropdown (default), which provides editing options through a drop-down selection, or to RadioButtons, which provides options through a group of radio buttons.

Because this is a choice field, the values are a bit more complicated. The basic format for a field is a single <Field> node. A choice field has the additional sub-nodes of <Default> and <CHOICES>. The <CHOICES> node further has one or more <CHOICE> nodes indicating the individual choices for the field.

The three basic attributes required for a <Field> node are:

  • Name: This is the InternalName used in SharePoint. It must be unique. The name is only seen by developers working on code that works with the list.
  • Display Name: This is the name that users see for the field. It is displayed in data entry screens and as the header for views of the list.
  • Type: This is the fundamental type of the field. For instance, Text, Note, URL, and Choice are all different fundamental types of fields.

If you have already created a choice site column with the UI in SharePoint you will have noticed that you have several display modes of a choice field:

Display choices using:

  • Drop-Down Menu
  • Radio Buttons
  • Checkboxes (allow multiple selections)

Types: MultiChoice, Choice, GridChoice

Format: DropDown, RadioButtons

When using a choice field, in addition to these attributes, you’ll also need the Format attribute to indicate the form of choice (DropDown), and the FillInChoice attribute which indicates whether the user can type in a response. Putting this all together, the CAML fragment for the field is:

<FieldTypes>
<FieldType>
<Field Name=”TypeName”>MyPeoplePicker</Field>
<Field Name=”ParentType”>Text</Field>
<Field Name=”TypeDisplayName”>Custom PeoplePicker</Field>
<Field Name=”TypeShortDescription”>Custom PeoplePicker</Field>
<Field Name=”UserCreatable”>TRUE</Field>
<Field Name=”ShowOnListCreate”>TRUE</Field>
<Field Name=”ShowOnSurveyCreate”>TRUE</Field>
<Field Name=”ShowOnDocumentLibrary”>TRUE</Field>
<Field Name=”ShowOnColumnTemplateCreate”>TRUE</Field>
<Field Name=”Sortable”>TRUE</Field>
<Field Name=”Filterable”>TRUE</Field>
<Field Name=”FieldTypeClass”>PeoplePicker.PeoplePickerField, PeoplePicker,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXX</Field>
<Field Name=”SQLType”>nvarchar</Field>
<PropertySchema>
<Fields>
<Field Type=”MultiChoice” Name=”userAttributes” DisplayName=”User Atrributes:” Format=”Dropdown” FillInChoice=”FALSE”>
<Default>DisplayName</Default>
<CHOICES>
<CHOICE>DisplayName</CHOICE>
<CHOICE>Email</CHOICE>
<CHOICE>PrincipalType</CHOICE>
</CHOICES>
</Field>
<Field Type=”Choice” Name=”SelectionSet” DisplayName=”Allow selection of:” Format=”RadioButtons”>
<Default>People only</Default>
<CHOICES>
<CHOICE>People only</CHOICE>
<CHOICE>People and Groups</CHOICE>
</CHOICES>
</Field>
</Fields>
</PropertySchema>
<RenderPattern Name=”DisplayPattern”>
<Switch>
<Expr>
<Column />

</Expr>
<Case Value=”” />
<Default>
<HTML/>
<Column HTMLEncode=”TRUE”/>
</Default>
</Switch>
</RenderPattern>
</FieldType>

If you’re looking for where the standard Sharepoint field type definitions are stored, they are here:

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\template\XML\FLDTYPES.XML

After the site column creation, you can use this fieldtype in a pagelayout with the CheckBoxChoiceField class.

Example:
<SharePointWebControls:CheckBoxChoiceField FieldName=”Product” runat=”server” ID=”CheckBoxChoiceField1″/>

Good Luck!

Advertisements

2 Responses to “Display choices using checkboxes in Field Types (multiple selections)”

  1. Jeyaraman said

    hi PANVEGA,

    thats is very good example for Custom Field type, but how to acheive the same for Type=”User”, that i mean creating custom ‘People and Group’ field… can you guide me?

  2. PANVEGA said

    The User and Group was only for my PeoplePicker Control properties important. I parsed the FieldType Display Choices and applied the enabled attributes in my PeoplePicker constructor.
    Read my post about a custom People Picker in combination with a Field Type

    access-custom-field-type-child-elements-customization


    developing-custom-field-types

    I hope that help you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: