2023-06-23 18:41:04 +00:00
|
|
|
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
|
|
|
|
|
2023-07-02 22:18:58 +00:00
|
|
|
Bind ValueBinder // Binds the current selected key to some variable.
|
2023-06-23 18:41:04 +00:00
|
|
|
Key string // The key that this RadioButton represents as a string.
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *RadioButton) isChecked() bool {
|
|
|
|
if c.Bind != nil {
|
2023-07-02 22:18:58 +00:00
|
|
|
return c.Bind.StringValue() == c.Key
|
2023-06-23 18:41:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *RadioButton) handleChange(event vugu.DOMEvent) {
|
|
|
|
if c.Bind == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if event.PropBool("target", "checked") {
|
2023-07-02 22:18:58 +00:00
|
|
|
c.Bind.SetStringValue(c.Key)
|
2023-06-23 18:41:04 +00:00
|
|
|
}
|
|
|
|
}
|