-
Notifications
You must be signed in to change notification settings - Fork 34
/
options.go
58 lines (49 loc) · 1.17 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package forms
import (
"github.com/iwind/TeaGo/types"
"html"
"net/http"
)
type Options struct {
Element `yaml:",inline"`
Options []*Option
}
type Option struct {
Text string
Value string
}
func NewOptions(title string, subtitle string) *Options {
return &Options{
Element: Element{
Title: title,
Subtitle: subtitle,
},
}
}
func (this *Options) AddOption(text string, value string) {
this.Options = append(this.Options, &Option{
Text: text,
Value: value,
})
}
func (this *Options) Super() *Element {
return &this.Element
}
func (this *Options) Compose() string {
result := `<select ` + this.ComposeAttrs(map[string]string{
"name": this.Namespace + "_" + this.Code,
}) + ` class="ui dropdown">`
for _, o := range this.Options {
result += `<option value="` + html.EscapeString(o.Value) + `"`
if o.Value == types.String(this.Value) {
result += ` selected="selected"`
}
result += ">" + html.EscapeString(o.Text) + `</option>`
}
result += "</select>"
return result
}
func (this *Options) ApplyRequest(req *http.Request) (value interface{}, skip bool, err error) {
value = req.Form.Get(this.Namespace + "_" + this.Code)
return value, false, nil
}