The checkbox editor renders a control that indicates a yes/no or true/false state.  By default, the editor renders a plain checkbox. Alternatively, the editor can be rendered as a toggle switch.

The checkbox editor is the default editor for boolean property types.

Rendered as checkbox
Rendered as toggle switch

Usage

Property values

Depending on the property type, the checkbox editor sets the following default values:

  • boolean: true if checked, false if unchecked.
  • numeric types: 1 if checked, 0 if unchecked.
  • string: "on" if checked, "off" if unchecked.

You can change the default values that get saved for this property by setting the CheckedValue and UncheckedValue properties of the CheckboxAttribute. These values must be convertible to the property type, otherwise, a configuration exception will be thrown on system startup.

Checkbox label

By default, no label is rendered next to the checkbox. You can render a checkbox label by setting the Label property of the CheckboxAttribute. In most cases, it will then no longer be necessary to display the field label, since the checkbox label provides enough information to the user. In that case, you can hide the field label by decorating the property with the HideLabelAttribute.

Render as toggle

If you prefer, the checkbox editor can be rendered as a toggle switch instead of a checkbox control. In that case, decorate the property with the ToggleAttribute. The toggle switch works in the same way as the checkbox control. The only difference is that you can set both the "on" and "off" state labels, instead of a single label. You do this by setting the OnLabel and OffLabel properties of the ToggleAttribute. If you don't set label properties, no toggle state labels will be displayed.

Example

public class SampleContent: IContentType
{
    // By convention; plain checkbox without label.
    public bool NoIndex { get; set; }

    // Set the checkbox label.
    [Checkbox(Label = "Hide in main navigation")]
    public bool HideInNavigation { get; set; }

    // Render checkbox for integer property.
    [Checkbox(CheckedValue = 100, UncheckedValue = 10)]
    public int IntegerValue { get; set; }

    // Render toggle switch for string property.
    [Toggle(CheckedValue = "enabled", UncheckedValue = "disabled", OnLabel = "ON", OffLabel = "OFF")]
    public string SwitchEnabled { get; set; }
}