Skip to content

Checkbox Field

A checkbox field combines a Checkbox with a label, a supporting text and an error text. Use it in forms. Clicking the label toggles the checkbox.

Checkbox Field

accepted := core.AutoState[bool](wnd)
newsletter := core.AutoState[bool](wnd)

VStack(
	CheckboxField("I accept the terms of use", accepted.Get()).
		InputValue(accepted).
		SupportingText("You can revoke your consent at any time."),
	CheckboxField("Subscribe to the newsletter", newsletter.Get()).
		InputValue(newsletter).
		ErrorText("Please confirm your email address first."),
).Alignment(Leading).Gap(L16)
Without InputValue the field renders as a read-only checkmark with its label, and the supporting and error texts are not shown.

Constructors

ConstructorDescription
func CheckboxField(label string, value bool) TCheckboxFieldCreates a checkbox field with the given label and value.

Methods

Some setters return DecoredView instead of TCheckboxField. Call them last in the chain.

MethodDescription
AccessibilityLabel(label string) DecoredViewAccessibilityLabel sets the label used for accessibility purposes.
Border(border Border) DecoredViewBorder sets the border styling of the checkbox field.
Disabled(b bool) TCheckboxFieldDisabled enables or disables user interaction with the checkbox field.
Enabled(b bool) TCheckboxFieldEnabled sets whether the checkbox field is interactive.
ErrorText(text string) TCheckboxFieldErrorText sets the validation or error message displayed below the field.
Frame(frame Frame) DecoredViewFrame sets the layout frame of the checkbox field, including size and positioning.
ID(id string) TCheckboxFieldID assigns a unique identifier to the checkbox field, useful for testing or referencing.
InputValue(inputValue *core.State[bool]) TCheckboxFieldInputValue binds the checkbox field to an external boolean state.
Name(name string) TCheckboxFieldName assigns a name to the checkbox field, useful for autocomplete.
Padding(padding Padding) DecoredViewPadding sets the inner spacing around the checkbox field.
SupportingText(text string) TCheckboxFieldSupportingText sets helper or secondary text shown below the label.
Visible(visible bool) DecoredViewVisible controls the visibility of the checkbox field; setting false hides it.
WithFrame(fn func(Frame) Frame) DecoredViewWithFrame applies a transformation function to the field’s frame and returns the updated component.

Related