Radio Buttons
A group of RadioButtonFields backed by a radio state group, with a preselected and a disabled option.

package main
import (
"fmt"
"go.wdy.de/nago/application"
"go.wdy.de/nago/presentation/core"
. "go.wdy.de/nago/presentation/ui"
"go.wdy.de/nago/presentation/ui/alert"
"go.wdy.de/nago/web/vuejs"
)
func main() {
application.Configure(func(cfg *application.Configurator) {
cfg.SetApplicationID("de.worldiety.tutorial")
cfg.Serve(vuejs.Dist())
cfg.RootView(".", func(wnd core.Window) core.View {
stateGroup := AutoRadioStateGroup(wnd, "my-state-group", 5)
if stateGroup.SelectedIndex() == -1 {
stateGroup.SetSelectedIndex(1)
}
showAlert := core.AutoState[bool](wnd)
return VStack(
alert.Dialog("Achtung", Text(fmt.Sprintf("Deine Eingabe: %v", stateGroup.SelectedIndex())), showAlert, alert.Ok()),
VStack(Each2(stateGroup.All(), func(idx int, checked *core.State[bool]) core.View {
return RadioButtonField(fmt.Sprintf("Option %d", idx), &stateGroup, idx).Disabled(idx == 0)
})...).Gap(L2),
PrimaryButton(func() {
showAlert.Set(true)
}).Title("Check"),
).Gap(L16).
Frame(Frame{}.MatchScreen())
})
}).Run()
}
View on GitHub ↗
· run it with go run go.wdy.de/nago/example/cmd/tutorial-15-radiobutton@latest