David Vogel
a587fea398
- 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
47 lines
848 B
Go
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)
|
|
}
|