forked from ungerik/go-start
/
checkbox.go
45 lines (40 loc) · 1.09 KB
/
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
package view
///////////////////////////////////////////////////////////////////////////////
// Checkbox
// Checkbox represents a HTML input element of type checkbox.
type Checkbox struct {
ViewBaseWithId
Name string
Label string
Checked bool
Disabled bool
Class string
}
func (self *Checkbox) Render(ctx *Context) (err error) {
ctx.Response.XML.OpenTag("input")
ctx.Response.XML.Attrib("id", self.ID())
ctx.Response.XML.AttribIfNotDefault("class", self.Class)
ctx.Response.XML.Attrib("type", "checkbox")
ctx.Response.XML.Attrib("name", self.Name)
ctx.Response.XML.Attrib("value", "true")
if self.Disabled {
ctx.Response.XML.Attrib("disabled", "disabled")
}
if self.Checked {
ctx.Response.XML.Attrib("checked", "checked")
}
ctx.Response.XML.CloseTag()
if self.Label != "" {
ctx.Response.XML.OpenTag("label").Attrib("for", self.ID()).Content(self.Label).CloseTag()
}
return nil
}
//func (self *Checkbox) SetName(name string) {
// self.Name = name
// ViewChanged(self)
//}
//
//func (self *Checkbox) SetLabel(label string) {
// self.Label = label
// ViewChanged(self)
//}