D3vugu-components/components/input/dropdown.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

47 lines
848 B
Go

package input
import (
"github.com/vugu/vugu"
)
// Dropdown provides several options that the user can choose.
type Dropdown struct {
AttrMap vugu.AttrMap
Bind ValueBinder // Binds the current selected key to some variable.
BindList ListBinder // Binds the list content to some list provider.
}
func (c *Dropdown) currentKey() string {
if c.Bind == nil {
return ""
}
return c.Bind.StringValue()
}
func (c *Dropdown) isKeySelected(key string) bool {
if c.Bind == nil {
return false
}
return key == c.Bind.StringValue()
}
func (c *Dropdown) keyValuePairs() []ListKeyValuePair {
if c.BindList == nil {
return nil
}
return c.BindList.ListKeyValuePairs()
}
func (c *Dropdown) handleChange(event vugu.DOMEvent) {
if c.Bind == nil {
return
}
val := event.PropString("target", "value")
c.Bind.SetStringValue(val)
}