Components

checkbox

A single boolean toggle. Use for consent declarations, confirmations, and opt-ins where the user must actively check a box to proceed.

A single boolean toggle. Use for consent declarations, confirmations, and opt-ins where the user must actively check a box to proceed.

Read Form Rules before using this component — keys, labels, required fields, expressions, visibility, and validation all follow shared conventions.

When to use

  • Terms-and-conditions acceptance
  • Consent declarations and confirmations
  • Single opt-in / opt-out toggles (a true/false question)

When NOT to use

Instead of checkbox, use…For…
multicheckboxSelecting one or more options from a fixed list
radioPicking exactly one option from 2–5 alternatives
customdropdownChoosing one option from a longer list

Props

PropTypeRequired?Description
labelstringrequiredInline checkbox label. Title Case for nouns, Sentence case for the declaration. Must be unique across the form.
requiredbooleanrequiredAlways false. The expression controls the runtime value — never set this to true directly.
defaultRequiredbooleanrequiredtrue for required fields, false for optional ones. This is the value the expression reads.
patternstringoptionalSet to "true" to require the box to actually be checked. Without this, Formly's required validator passes even when the value is false.
hideLabelbooleanoptionalSet to true to suppress the outer label wrapper so the checkbox label is rendered inline only. Required for consent-style checkboxes.
formCheckstringoptionalLayout style. Always "default".
descriptionstringoptionalSecondary helper text below the checkbox.
tooltipstringoptionalShort help text shown as an icon tooltip next to the label.
indeterminatebooleanoptionalVisual indeterminate state. Defaults to false. Optional, but by convention always include it set to false when authoring.
hideFieldbooleanoptionalHides the field and excludes its value from submission. Use expressions["props.hideField"] to toggle. Do not use hide directly.

The required mechanism

Every checkbox field must include this exact expression, regardless of whether the field is required or optional. Never omit it, never change it.

"expressions": {
  "props.required": "!(field?.props?.hideField || field?.hide) && field?.props?.defaultRequired"
}

For required consent checkboxes, also set props.pattern: "true" — the required validator alone considers false a valid value, so the user could submit the form without actually checking the box.

  • To make a field required: set defaultRequired: true and pattern: "true".
  • To make a field optional: set defaultRequired: false.

Examples

{
  "key": "AGREE_TO_TERMS",
  "type": "checkbox",
  "props": {
    "label": "I agree to the terms and conditions",
    "required": false,
    "defaultRequired": true,
    "pattern": "true",
    "hideLabel": true,
    "indeterminate": false
  },
  "expressions": {
    "props.required": "!(field?.props?.hideField || field?.hide) && field?.props?.defaultRequired"
  },
  "validation": {
    "messages": {
      "required": "You must accept the terms to proceed."
    }
  }
}
{
  "key": "CONSENT_TO_RECORDS",
  "type": "checkbox",
  "props": {
    "label": "I understand and expressly consent that the information I provide will be recorded in the register.",
    "required": false,
    "defaultRequired": true,
    "pattern": "true",
    "formCheck": "default",
    "hideLabel": true,
    "indeterminate": false
  },
  "expressions": {
    "props.required": "!(field?.props?.hideField || field?.hide) && field?.props?.defaultRequired"
  },
  "validation": {
    "messages": {
      "required": "You must accept the declaration to proceed."
    }
  }
}

Optional opt-in

{
  "key": "SUBSCRIBE_TO_UPDATES",
  "type": "checkbox",
  "props": {
    "label": "Send me updates about this service",
    "required": false,
    "defaultRequired": false,
    "hideLabel": true,
    "indeterminate": false
  },
  "expressions": {
    "props.required": "!(field?.props?.hideField || field?.hide) && field?.props?.defaultRequired"
  }
}

Checklist

  • key is UPPER_SNAKE_CASE and unique across the entire form
  • props.label is present, unique, and correctly cased
  • Field is nested at the correct depth: sections > formly-group > block > checkbox
  • required: false is set (never true)
  • defaultRequired is set (true or false)
  • expressions["props.required"] is present with the exact required expression
  • props.pattern: "true" is set for any required consent / opt-in checkbox
  • props.hideLabel: true is set to avoid duplicate label text in the UI
  • props.indeterminate: false is included (optional, but set by convention)
  • validation.messages.required is present for required checkboxes
  • No defaultValue: true on consent fields — the user must actively opt in
  • Not using checkbox for multi-select lists (see multicheckbox)

On this page