forked from ungerik/go-start
/
textfield.go
89 lines (78 loc) · 1.98 KB
/
textfield.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package view
type TextFieldType int
const (
NormalTextField TextFieldType = iota
PasswordTextField
EmailTextField
)
///////////////////////////////////////////////////////////////////////////////
// TextField
type TextField struct {
ViewBaseWithId
Text string
Name string
Size int
MaxLength int
Type TextFieldType
Readonly bool
Disabled bool
TabIndex int
Class string
Placeholder string
}
func (self *TextField) Render(ctx *Context) (err error) {
ctx.Response.XML.OpenTag("input")
ctx.Response.XML.AttribIfNotDefault("id", self.id)
ctx.Response.XML.AttribIfNotDefault("class", self.Class)
ctx.Response.XML.Attrib("name", self.Name)
ctx.Response.XML.AttribIfNotDefault("tabindex", self.TabIndex)
if self.Readonly {
ctx.Response.XML.Attrib("readonly", "readonly")
}
if self.Disabled {
ctx.Response.XML.Attrib("disabled", "disabled")
}
switch self.Type {
case PasswordTextField:
ctx.Response.XML.Attrib("type", "password")
case EmailTextField:
ctx.Response.XML.Attrib("type", "email")
default:
ctx.Response.XML.Attrib("type", "text")
}
ctx.Response.XML.AttribIfNotDefault("size", self.Size)
ctx.Response.XML.AttribIfNotDefault("maxlength", self.MaxLength)
ctx.Response.XML.AttribIfNotDefault("placeholder", self.Placeholder)
ctx.Response.XML.Attrib("value", self.Text)
ctx.Response.XML.CloseTag()
return nil
}
//func (self *TextField) SetText(text string) {
// self.Text = text
// ViewChanged(self)
//}
//
//func (self *TextField) SetName(name string) {
// self.Name = name
// ViewChanged(self)
//}
//
//func (self *TextField) SetReadonly(readonly bool) {
// self.Readonly = readonly
// ViewChanged(self)
//}
//
//func (self *TextField) SetMaxLength(maxlength int) {
// self.MaxLength = maxlength
// ViewChanged(self)
//}
//
//func (self *TextField) SetTabIndex(tabindex int) {
// self.TabIndex = tabindex
// ViewChanged(self)
//}
//
//func (self *TextField) SetClass(class string) {
// self.Class = class
// ViewChanged(self)
//}