2023-05-27 11:37:40 +00:00
|
|
|
package input
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/vugu/vugu"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Dropdown provides several options that the user can choose.
|
|
|
|
type Dropdown struct {
|
|
|
|
AttrMap vugu.AttrMap
|
|
|
|
|
2023-07-02 22:18:58 +00:00
|
|
|
Bind ValueBinder // Binds the current selected key to some variable.
|
2023-05-27 11:37:40 +00:00
|
|
|
BindList ListBinder // Binds the list content to some list provider.
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Dropdown) currentKey() string {
|
|
|
|
if c.Bind == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2023-07-02 22:18:58 +00:00
|
|
|
return c.Bind.StringValue()
|
2023-05-27 11:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Dropdown) isKeySelected(key string) bool {
|
|
|
|
if c.Bind == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-07-02 22:18:58 +00:00
|
|
|
return key == c.Bind.StringValue()
|
2023-05-27 11:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
2023-07-02 22:18:58 +00:00
|
|
|
c.Bind.SetStringValue(val)
|
2023-05-27 11:37:40 +00:00
|
|
|
}
|