-
Notifications
You must be signed in to change notification settings - Fork 34
/
checkbox.go
47 lines (40 loc) · 962 Bytes
/
checkbox.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
package forms
import (
"github.com/iwind/TeaGo/types"
"net/http"
)
type CheckBox struct {
Element
IsChecked bool `yaml:"isChecked" json:"isChecked"`
Label string `yaml:"label" json:"label"`
}
func NewCheckBox(title string, subTitle string) *CheckBox {
return &CheckBox{
Element: Element{
Title: title,
Subtitle: subTitle,
},
}
}
func (this *CheckBox) Super() *Element {
return &this.Element
}
func (this *CheckBox) Compose() string {
attrs := map[string]string{
"name": this.Namespace + "_" + this.Code,
}
if this.IsChecked {
attrs["checked"] = "checked"
}
attrs["value"] = types.String(this.Value)
return `
<div class="ui checkbox">
<input type="checkbox"` + this.ComposeAttrs(attrs) + `/>
<label>` + this.Label + `</label>
</div>
`
}
func (this *CheckBox) ApplyRequest(req *http.Request) (value interface{}, skip bool, err error) {
value = req.Form.Get(this.Namespace + "_" + this.Code)
return value, false, nil
}