D3vugu-components/components/input/radio-button.go
David Vogel a587fea398 Rework value and list binder
- Rename FieldBinder to ValueBinder
- Split ValueBinder interface into ValueGetter, ValueSetter and HTMLInputTyper
- Add non pointer types to ValueBindAny.StringValue
- Move encoding.TextMarshaler in type switch
- Simplify ListBinder, and reuse ValueBinder logic
- Add ListBindGenericValues type
2023-07-03 00:18:58 +02:00

33 lines
668 B
Go

package input
import (
"github.com/vugu/vugu"
)
// RadioButton provides an option that the user can select.
// A group of RadioButtons is defined when they share a data binding.
type RadioButton struct {
AttrMap vugu.AttrMap
Bind ValueBinder // Binds the current selected key to some variable.
Key string // The key that this RadioButton represents as a string.
}
func (c *RadioButton) isChecked() bool {
if c.Bind != nil {
return c.Bind.StringValue() == c.Key
}
return false
}
func (c *RadioButton) handleChange(event vugu.DOMEvent) {
if c.Bind == nil {
return
}
if event.PropBool("target", "checked") {
c.Bind.SetStringValue(c.Key)
}
}