Checkbox

Checkbox field, wraps <input type="checkbox">.

Checkbox
//<code-header>
fiddle.title = 'Checkbox';
//</code-header>
new Checkbox({
    appendTo : targetElement,
    text     : 'Unchecked'
});

new Checkbox({
    appendTo : targetElement,
    checked  : true,
    text     : 'Checked'
});

new Checkbox({
    appendTo : targetElement,
    disabled : true,
    text     : 'Disabled & checked',
    checked  : true
});

new Checkbox({
    appendTo : targetElement,
    disabled : true,
    text     : 'Disabled'
});

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:

Checkbox text label
//<code-header>
fiddle.title = 'Checkbox text label';
//</code-header>
new Checkbox({
    appendTo : targetElement,
    text     : 'With text'
});

new Checkbox({
    appendTo : targetElement,
    label    : 'With label'
});

This field can be used as an editor for the Column.

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:

Checkbox items
//<code-header>
fiddle.title = 'Checkbox items';
//</code-header>
new Checkbox({
    appendTo     : targetElement,
    text         : 'Single item',
    autoCollapse : true,
    checked      : true,
    container    : [{
        type        : 'textfield',
        placeholder : 'Additional info...',
        flex        : 1
    }]
});

new Checkbox({
    appendTo     : targetElement,
    text         : 'Two items',
    autoCollapse : true,
    inline       : true,  // can also use false to wrap a single item
    container    : {
        from : {
            type        : 'textfield',
            placeholder : 'From...',
            flex        : 1
        },
        to : {
            type        : 'textfield',
            placeholder : 'To...',
            flex        : 1,
            style       : 'margin-inline-start: 1em'
        }
    }
});

new Checkbox({
    appendTo     : targetElement,
    text         : 'Child form',
    autoCollapse : true,
    checked      : true,
    container    : {
        from : {
            labelPosition : 'above',
            type          : 'textfield',
            label         : 'From',
            width         : 'auto'
        },
        to : {
            labelPosition : 'above',
            type          : 'textfield',
            label         : 'To',
            width         : 'auto'
        }
    }
});

Configs

112

Common

listenersEvents

Other

autoCollapse: Boolean | function= false

Specify true to automatically collapse the field's container when the field is not checked.

Alternatively, this can be a function that returns the desired collapse state when passed the field instance as its one parameter.

Returns: Boolean

The checked state. The same as value.

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.

color: String

Checkbox color, must have match in CSS

text: String

Text to display on checkbox label

The value to provide for this widget in values when it is not checked.

A value of undefined will cause this widget to not include its value when it is unchecked.

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

columnWidget
nameField
rtlRTL
spanWidget

Accessibility

ariaLabelWidget
keyMapKeyMap

Container

inlineField

CSS

clsWidget
htmlClsWidget
styleWidget
uiWidget

DOM

adoptWidget
appendToWidget
contentWidget
datasetWidget
htmlWidget
idWidget
tagWidget
titleWidget

Float & align

alignWidget
anchorWidget
centeredWidget
draggableWidget
floatingWidget
xWidget
yWidget

Input element

Label

hintField
labelLabelable
labelClsLabelable
labelPositionLabelable
labelsField
labelWidthLabelable

Layout

alignSelfWidget
dockWidget
flexWidget
heightWidget
hiddenWidget
marginWidget
maxHeightWidget
maxWidthWidget
minHeightWidget
minWidthWidget
textAlignWidget
weightWidget
widthWidget

Misc

badgeBadge
dataFieldWidget
disabledWidget
localeClassLocalizable
localizableLocalizable
maskedWidget
ownerWidget
refWidget
rippleWidget
tabWidget
tooltipWidget

Scrolling

Properties

84

Class hierarchy

isCheckbox: Boolean= truereadonly
Identifies an object as an instance of Checkbox class, or subclass thereof.
isCheckbox: Boolean= truereadonlystatic
Identifies an object as an instance of Checkbox class, or subclass thereof.
isBadgeBadge
isDelayableDelayable
isEventsEvents
isFieldField
isKeyMapKeyMap
isLabelableLabelable
isLocalizableLocalizable
isValidatableValidatable
isWidgetWidget

Other

The checked state. The same as value.

name: String

Get/set label

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

$namestaticWidget
columnWidget
inputField
isEmptyField
isValidField
rtlRTL
spanWidget
typestaticWidget

Accessibility

keyMapKeyMap

CSS

clsWidget

DOM

appendToWidget
contentWidget
datasetWidget
elementWidget
htmlWidget
idWidget
styleWidget

Float & align

xWidget
yWidget

Layout

alignSelfWidget
flexWidget
heightWidget
marginWidget
maxHeightWidget
maxWidthWidget
minHeightWidget
minWidthWidget
widthWidget

Lifecycle

configBase

Misc

badgeBadge
cellInfoWidget
disabledWidget
errorTipValidatable
labelLabelable
localeHelperLocalizable
localeManagerLocalizable
refWidget
tabWidget
tooltipWidget

Visibility

hiddenWidget
isVisibleWidget

Widget hierarchy

ownerWidget
parentWidget

Functions

67

Other

Check the box

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

Uncheck the box

clearField
clearErrorValidatable
composeWidget
createOnFrameDelayable
disableWidget
enableWidget
focusWidget
getErrorsValidatable
LstaticLocalizable
maskWidget
onEvents
recomposeWidget
relayAllEvents
selectField
setErrorValidatable
triggerEvents
unEvents
unmaskWidget

Configuration

applyDefaultsstaticBase

Events

Float & align

alignToWidget
setXYWidget
showByWidget
toFrontWidget

Lifecycle

createstaticWidget
destroystaticBase
initClassstaticWidget

Misc

attachTooltipstaticWidget
fromElementstaticWidget
fromSelectorstaticWidget
getByIdstaticWidget
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Visibility

hideWidget
showWidget

Widget hierarchy

closestWidget
containsWidget
ownsWidget
queryWidget
queryAllWidget
upWidget

Events

21

User performed the default action (toggled the checkbox)

// Adding a listener using the "on" method
checkbox.on('action', ({ source, checked, value, valid, oldValue, userAction, event }) => {

});
ParameterTypeDescription
sourceCheckbox

Checkbox

checkedBoolean

Checked state (=value)

valueBoolean

This field's value

validBoolean

True if this field is in a valid state

oldValueBoolean

This field's previous value

userActionBoolean

Triggered by user taking an action (true) or by setting a value (false)

eventEvent

The triggering DOM event if any

Fired before checkbox is toggled. Returning false from a listener prevents the checkbox from being toggled.

// Adding a listener using the "on" method
checkbox.on('beforeChange', ({ source, checked, value, oldValue, userAction, valid, event }) => {

});
ParameterTypeDescription
sourceCheckbox

Checkbox

checkedBoolean

Checked state (=value)

valueBoolean

This field's value

oldValueBoolean

This field's previous value

userActionBoolean

Triggered by user taking an action (true) or by setting a value (false)

validBoolean

True if this field is in a valid state.

eventEvent

The triggering DOM event if any

Fired when checkbox is toggled

// Adding a listener using the "on" method
checkbox.on('change', ({ source, checked, value, oldValue, userAction, valid, event }) => {

});
ParameterTypeDescription
sourceCheckbox

Checkbox

checkedBoolean

Checked state (=value)

valueBoolean

This field's value

oldValueBoolean

This field's previous value

userActionBoolean

Triggered by user taking an action (true) or by setting a value (false)

validBoolean

True if this field is in a valid state.

eventEvent

The triggering DOM event if any

Fires when the checkbox is clicked

// Adding a listener using the "on" method
checkbox.on('click', ({ source, event }) => {

});
ParameterTypeDescription
sourceCheckbox

The checkbox

eventEvent

DOM event

catchAllEvents
clearField
destroyEvents
focusInWidget
focusOutWidget
hideWidget
inputField
paintWidget
readOnlyWidget
recomposeWidget
resizeWidget
showWidget
triggerField

Event handlers

21

User performed the default action (toggled the checkbox)

new Checkbox({
    onAction({ source, checked, value, valid, oldValue, userAction, event }) {

    }
});
ParameterTypeDescription
sourceCheckbox

Checkbox

checkedBoolean

Checked state (=value)

valueBoolean

This field's value

validBoolean

True if this field is in a valid state

oldValueBoolean

This field's previous value

userActionBoolean

Triggered by user taking an action (true) or by setting a value (false)

eventEvent

The triggering DOM event if any

Called before checkbox is toggled. Returning false from a listener prevents the checkbox from being toggled.

new Checkbox({
    onBeforeChange({ source, checked, value, oldValue, userAction, valid, event }) {

    }
});
ParameterTypeDescription
sourceCheckbox

Checkbox

checkedBoolean

Checked state (=value)

valueBoolean

This field's value

oldValueBoolean

This field's previous value

userActionBoolean

Triggered by user taking an action (true) or by setting a value (false)

validBoolean

True if this field is in a valid state.

eventEvent

The triggering DOM event if any

Called when checkbox is toggled

new Checkbox({
    onChange({ source, checked, value, oldValue, userAction, valid, event }) {

    }
});
ParameterTypeDescription
sourceCheckbox

Checkbox

checkedBoolean

Checked state (=value)

valueBoolean

This field's value

oldValueBoolean

This field's previous value

userActionBoolean

Triggered by user taking an action (true) or by setting a value (false)

validBoolean

True if this field is in a valid state.

eventEvent

The triggering DOM event if any

Called when the checkbox is clicked

new Checkbox({
    onClick({ source, event }) {

    }
});
ParameterTypeDescription
sourceCheckbox

The checkbox

eventEvent

DOM event

onClearField
onDestroyEvents
onFocusInWidget
onHideWidget
onInputField
onPaintWidget
onResizeWidget
onShowWidget

Typedefs

7

CSS variables

62
NameDescription
--b-checkbox-sizeCheckbox box size
--b-checkbox-border-radiusCheckbox box border-radius
--b-checkbox-check-font-sizeCheckbox checkmark font size
--b-checkbox-inner-gapGap between checkbox box and text
--b-checkbox-ring-contentCheckbox ring content, used by Material3 theme to display a ring around the checkbox
--b-checkbox-backgroundCheckbox box background
--b-checkbox-border-widthCheckbox box border-width
--b-checkbox-border-colorCheckbox box border-color
Active
--b-checkbox-ring-active-opacityActive checkbox ring opacity (Material3 theme)
Checked
--b-checkbox-checked-backgroundChecked checkbox box background
--b-checkbox-checked-border-colorChecked checkbox box border-color
--b-checkbox-checked-check-contentChecked checkbox box content (checkmark icon)
--b-checkbox-checked-check-colorChecked checkbox checkmark color
--b-checkbox-checked-hover-backgroundHovered checked checkbox box background
Disabled
--b-checkbox-disabled-opacityDisabled checkbox opacity
--b-checkbox-disabled-checked-check-colorDisabled checked checkbox checkmark color
--b-checkbox-disabled-checked-backgroundDisabled checked checkbox box background
--b-checkbox-disabled-backgroundDisabled checkbox box background
Focused
--b-checkbox-focus-outline-widthFocused checkbox box outline-width
--b-checkbox-focus-outline-offsetFocused checkbox box outline-offset
--b-checkbox-focus-outline-colorFocused checkbox box outline-color
--b-checkbox-ring-focus-opacityFocused checkbox ring opacity (Material3 theme)
Hovered
--b-checkbox-hover-backgroundHovered checkbox box background
--b-checkbox-hover-border-colorHovered checkbox box border-color
--b-checkbox-ring-hover-opacityHovered checkbox ring opacity (Material3 theme)

Inherited