-
Notifications
You must be signed in to change notification settings - Fork 58
/
input.go
54 lines (46 loc) · 1019 Bytes
/
input.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
package dom
func (d *Document) NewInput(typ string) *Input {
e := d.CreateElement("input")
inp := &Input{HTMLElement{*e}}
inp.SetType(typ)
return inp
}
func NewInput(typ string) *Input {
return Doc.NewInput(typ)
}
type Input struct {
HTMLElement
}
func (inp *Input) Value() string {
return inp.v.Get("value").String()
}
func (inp *Input) SetType(typ string) {
inp.SetAttribute("type", typ)
}
func (inp *Input) SetName(name string) {
inp.SetAttribute("name", name)
}
func (inp *Input) SetValue(val interface{}) {
inp.v.Set("value", val)
}
func (inp *Input) OnChange(h EventHandler) {
inp.AddEventListener("change", h)
}
func (inp *Input) OnInput(h EventHandler) {
inp.AddEventListener("input", h)
}
func (d *Document) NewButton(s string) *Button {
e := d.CreateElement("button")
b := &Button{*e}
b.SetInnerHTML(s)
return b
}
func NewButton(s string) *Button {
return Doc.NewButton(s)
}
type Button struct {
Element
}
func (b *Button) OnClick(h EventHandler) {
b.AddEventListener("click", h)
}