Create yes/no fields
To learn more about the different steps to create a custom field, read the For developers: Create custom fields for product types article.
Here is a list of the things that are specific for the yes/no choice field:
- Field CLR type: typeof(bool).FullName
- User friendly data type: UserFriendlyDataType.YesNo
- DB type: BIT
- Field type: typeof(ChoiceField).FullName
When creating a yes/no field you must also perform the following in:
- Where you set the properties of the field definition, you must set additional property
RenderChoiceAs
. It gets or sets how the choices are rendered in the UI. Set this property to the following value: RenderChoicesAs.SingleCheckBox.
- Where you create the field definition, you must also create a choice item that represents the yes/no question.
To do this perform the following:
- Create an instance of the
ChoiceItem
class.
- Set the
Text
property of the instance to the question.
- Set the
Value
property of the instance to true.
- Add the item to a
List
of ChoiceItem
.
- Serialize the list using a
JavaScriptSerializer
instance.
- Set the
Choices
property of the WcfFieldDefinition
instance to the serialized value.
Use the following code example: