-
Notifications
You must be signed in to change notification settings - Fork 5
/
tag.go
58 lines (50 loc) · 954 Bytes
/
tag.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
package domui
import (
"syscall/js"
)
func Tag(name string) func(specs ...Spec) *Node {
return func(specs ...Spec) *Node {
node := &Node{
Kind: TagNode,
Text: name,
}
for _, spec := range specs {
node.ApplySpec(spec)
}
// bind input state to node
if name == "input" {
v, ok := node.Attributes.Get("type")
var typ string
if ok {
typ = v.(string)
} else {
typ = "text"
}
switch typ {
case "checkbox", "radio":
node.ApplySpec(On("input")(func(elem js.Value) {
node.Attributes.Set("checked", elem.Get("checked").String())
}))
case "", "color",
"date",
"file",
"datetime-local",
"email",
"month",
"number",
"password",
"range",
"search",
"tel",
"text",
"time",
"url",
"week":
node.ApplySpec(On("input")(func(elem js.Value) {
node.Attributes.Set("value", elem.Get("value").String())
}))
}
}
return node
}
}