diff --git a/selectbox.go b/selectbox.go index 4ebae5f..ef5bab1 100644 --- a/selectbox.go +++ b/selectbox.go @@ -115,7 +115,7 @@ func (w *SelectBox) AddItem(label string, value interface{}, f func()) { // TODO: RemoveItem() -// Value returns the currently selected item in the SelectBox. +// GetValue returns the currently selected item in the SelectBox. // // Returns the SelectValue and true on success, and the Label or underlying Value // can be read from the SelectValue struct. If no valid option is selected, the @@ -130,6 +130,28 @@ func (w *SelectBox) GetValue() (SelectValue, bool) { return SelectValue{}, false } +// SetValueByLabel sets the currently selected option to the given label. +func (w *SelectBox) SetValueByLabel(label string) bool { + for _, option := range w.values { + if option.Label == label { + w.textVariable = option.Label + return true + } + } + return false +} + +// SetValue sets the currently selected option to the given value. +func (w *SelectBox) SetValue(value interface{}) bool { + for _, option := range w.values { + if option.Value == value { + w.textVariable = option.Label + return true + } + } + return false +} + // Compute to re-evaluate the button state (in the case of radio buttons where // a different button will affect the state of this one when clicked). func (w *SelectBox) Compute(e render.Engine) {