d821d392/html_components/select-input.go
1970-01-01 00:00:00 +00:00

27 lines
547 B
Go

package html_components
type SelectInputOption struct {
Label string
Value string
Selected bool
}
type SelectInput struct {
Label string
Name string
Options []SelectInputOption
HideLabel bool
}
func (s SelectInput) SetSelectedOption(selectedFunc func(option SelectInputOption) bool) SelectInput {
newOptions := make([]SelectInputOption, len(s.Options))
for index, option := range s.Options {
if selectedFunc(option) {
option.Selected = true
}
newOptions[index] = option
}
s.Options = newOptions
return s
}