Skip to Content
Onevra

Checkbox

Turns an option on or off, for choices that apply when a form is submitted.

Loading the live example…

checkbox.go
import (
	"github.com/egoist/mygo/ui"
	"github.com/oneo-me/onevra/source/components"
)

type signup struct {
	terms, newsletter bool
}

func (s *signup) View(c *ui.Context) {
	ui.Column(c).Gap(12).Children(func() {
		components.Checkbox(c, &s.terms, "I accept the terms")
		components.Checkbox(c, &s.newsletter, "Send me product news")
		components.Button(c, "Create account", components.ButtonPrimary).Disabled(!s.terms)
	})
}
Source

components.Checkbox toggles a *bool, and its label is also its accessible name. For a setting that applies at once, use a switch.

API

Checkbox

func Checkbox(c *ui.Context, checked *bool, label string) ui.Element

Checkbox creates a check box toggling *checked, with a label. The label is also the accessible name.

pkg.go.dev
Edit this page on GitHub

On this page