Skip to main content

Checkbox

The Checkbox widget provides a toggleable input control that allows users to select or deselect an option.

States

StateTypeDefaultDescription
valueboolFalseWhether the checkbox is checked

Properties

PropertyTypeDefaultDescription
labelstring""Text displayed next to the checkbox
default_valueboolFalseInitial checked state of the checkbox
requiredboolFalseWhether the checkbox must be checked
disabledboolFalseWhether the checkbox is disabled

Examples

Basic Checkbox

package main

import (
"github.com/trysourcetool/sourcetool-go"
"github.com/trysourcetool/sourcetool-go/checkbox"
)

func main() {
func page(ui sourcetool.UIBuilder) error {
// Create a basic checkbox
checkbox := ui.Checkbox("Subscribe to newsletter")
}
}

Default Checkbox

// Create a default checkbox
checkbox := ui.Checkbox("Subscribe to newsletter", checkbox.DefaultValue(true))

Required Checkbox

// Create a required checkbox with description
checkbox := ui.Checkbox("Subscribe to newsletter", checkbox.Required(true))

Disabled Checkbox

// Create a disabled checkbox
checkbox := ui.Checkbox("Subscribe to newsletter", checkbox.Disabled(true))
  • CheckboxGroup - For managing multiple related checkboxes
  • Radio - For mutually exclusive options (unlike checkboxes)