v7.3.0

Checkbox
Widget

A checkbox field that wraps <input type="checkbox"> and provides a boolean toggle with an optional text label to the right and configurable color. The field's checked state maps to its value, and the values returned when checked or unchecked are controlled via checkedValue and uncheckedValue. This field can be used as a cell editor in a Grid.

const checkbox = new Checkbox({
    label   : 'Agree to terms',
    text    : 'I accept',
    checked : false,
    appendTo : document.body
});

Color can be specified, and you can optionally configure text to display in a label to the right of the checkbox in addition to a standard field label:

Useful configs and properties

Config Description
checked Initial checked state
text Label text displayed to the right of the checkbox
color Checkbox color (must have a matching CSS rule)
checkedValue Value provided when checked
uncheckedValue Value provided when unchecked
label Field label displayed beside the checkbox

Nested Items

A checkbox can also have a container of additional items. These items can be displayed immediately following the field's label (which is the default when there is only one item) or below the checkbox. This can be controlled using the inline config.

In the demo below notice how additional fields are displayed when the checkboxes are checked:

See also

  • SlideToggle - Toggle switch variation of Checkbox
  • CheckboxGroup - Group widget for multiple-selection checkboxes
  • Radio - Radio button for single-selection groups
No results

Configs

Configs are options you supply in a configuration object when creating an instance of this class
  • The checked state. The same as value.

    Has a corresponding runtime checked property.

  • The value to provide for this widget in values when it is checked. A value of undefined will cause this widget not to include its value when checked.

  • Checkbox color, must have match in CSS

  • Text to display on checkbox label

  • The value of the checkbox. This is the same as checked.

    Has a corresponding runtime value property.

Properties

Properties are getters/setters or publicly accessible variables on this class
  • isCheckbox : Booleantrue
    READONLY
    static
    ADVANCED
    Identifies an object as an instance of Checkbox class, or subclass thereof.

Functions

Functions are methods available for calling on the class
    • check( )

      Check the box

    • internalOnChange( )
      private

      Triggers events when user toggles the checkbox


      Triggers: beforeChange, change, action

    • toggle( )

      Toggle checked state. If you want to force a certain state, assign to checked instead.

    • triggerChange( )
      private

      Triggers events when checked state is changed


      Triggers: beforeChange, change, action

    • Uncheck the box

    Events

    Events are triggered for certain actions in this class and can be listened for to react to those actions in your code

    Event handlers

    Event handlers are callbacks called as a result of certain actions in this class

    CSS variables

    CSS variables that can be set to adjust appearance
    Name Description
    --b-checkbox-background Checkbox box background
    --b-checkbox-border-color Checkbox box border-color
    --b-checkbox-border-radius Checkbox box border-radius
    --b-checkbox-border-radius Checkbox box border-radius
    --b-checkbox-border-width Checkbox box border-width
    --b-checkbox-check-font-size Checkbox checkmark font size
    --b-checkbox-inner-gap Gap between checkbox box and text
    --b-checkbox-ring-content Checkbox ring content, used by Material3 theme to display a ring around the checkbox
    --b-checkbox-size Checkbox box size
    Active
    --b-checkbox-ring-active-opacity Active checkbox ring opacity (Material3 theme)
    Checked
    --b-checkbox-checked-background Checked checkbox box background
    --b-checkbox-checked-border-color Checked checkbox box border-color
    --b-checkbox-checked-check-color Checked checkbox checkmark color
    --b-checkbox-checked-check-content Checked checkbox box content (checkmark icon)
    --b-checkbox-checked-hover-background Hovered checked checkbox box background
    Disabled
    --b-checkbox-disabled-background Disabled checkbox box background
    --b-checkbox-disabled-checked-background Disabled checked checkbox box background
    --b-checkbox-disabled-checked-check-color Disabled checked checkbox checkmark color
    --b-checkbox-disabled-opacity Disabled checkbox opacity
    Focused
    --b-checkbox-focus-outline-color Focused checkbox box outline-color
    --b-checkbox-focus-outline-offset Focused checkbox box outline-offset
    --b-checkbox-focus-outline-width Focused checkbox box outline-width
    --b-checkbox-ring-focus-opacity Focused checkbox ring opacity (Material3 theme)
    Hovered
    --b-checkbox-hover-background Hovered checkbox box background
    --b-checkbox-hover-border-color Hovered checkbox box border-color
    --b-checkbox-ring-hover-opacity Hovered checkbox ring opacity (Material3 theme)
    type: checkbox

    Source path

    Core/widget/Checkbox.js

    Contents