-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.go
50 lines (43 loc) · 944 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
package livedom
func (d *Document) NewInput(typ string) *Input {
e := d.CreateElement("input")
inp := &Input{*e}
inp.SetType(typ)
return inp
}
type Input struct {
Element
}
func AsInput(e *Element) *Input {
return &Input{Element: *e}
}
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
}
type Button struct {
Element
}
func (b *Button) OnClick(h EventHandler) {
b.AddEventListener("click", h)
}