logo

Pacis

Github
  1. Docs
  2. Checkbox

Checkbox

A control that allows the user to toggle between checked and not checked.

Checkbox()

Usage

import (
	. "github.com/canpacis/pacis/ui/components"
)
Checkbox()

Examples

With label

Checkbox(Text("Label"))

Default checked

Checkbox(Checked)

With an event handler

Checkbox(On("changed", "alert($event.detail.checked)")),

API

Events

EventDescription
initFires upon initialization and sends its initial state.
changedFires when the checkbox state changes. You can find the boolean value on the $event.detail object

Functions

SignatureDescription
toggleCheckbox(): voidToggles the checkbox state.
isChecked(): booleanReturns the checkbox state.

Go Attributes

SignatureDescription
ToggleCheckboxToggles the checkbox on click.
ToggleChecboxOn(string)Toggles the checkbox upon given event.

State

You can reach to a checkbox's state outside of the component by providing an explicit id to it.

Checkbox(ID("test"))
// Somewhere else
Div(X("text", "$checkbox('test').isChecked()")) // <- use the api via the alpine magic

Every checkbox, whether you provide an explicit id or not, is registered to this global store upon initialization.