-
Notifications
You must be signed in to change notification settings - Fork 34
/
textbox.go
57 lines (46 loc) · 1.11 KB
/
textbox.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
package forms
import (
"fmt"
"github.com/iwind/TeaGo/types"
"net/http"
)
type TextBox struct {
Element
MaxLength int
Placeholder string
Cols int
Rows int
}
func NewTextBox(title string, subTitle string) *TextBox {
return &TextBox{
Element: Element{
Title: title,
Subtitle: subTitle,
},
}
}
func (this *TextBox) Super() *Element {
return &this.Element
}
func (this *TextBox) Compose() string {
attrs := map[string]string{}
if this.MaxLength > 0 {
attrs["maxlength"] = fmt.Sprintf("%d", this.MaxLength)
}
if len(this.Placeholder) > 0 {
attrs["placeholder"] = this.Placeholder
}
if this.Cols > 0 {
attrs["cols"] = fmt.Sprintf("%d", this.Cols)
}
if this.Rows > 0 {
attrs["rows"] = fmt.Sprintf("%d", this.Rows)
}
valueString := types.String(this.Value)
attrs["name"] = this.Namespace + "_" + this.Code
return `<textarea ` + this.ComposeAttrs(attrs) + `>` + valueString + `</textarea>`
}
func (this *TextBox) ApplyRequest(req *http.Request) (value interface{}, skip bool, err error) {
value = req.Form.Get(this.Namespace + "_" + this.Code)
return value, false, nil
}