-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap4.go
96 lines (71 loc) · 2.31 KB
/
bootstrap4.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
90
91
92
93
94
95
96
package decorators
import (
"golang.org/x/net/html"
"github.com/cj123/formulate"
)
// BootstrapDecorator implements a form layout using Bootstrap 4.
type BootstrapDecorator struct{}
var _ formulate.Decorator = &BootstrapDecorator{}
func (b BootstrapDecorator) FieldWrapper(n *html.Node, field formulate.StructField) {
b.col8(n)
}
func (b BootstrapDecorator) HelpText(n *html.Node, field formulate.StructField) {
n.Data = "div"
formulate.AppendClass(n, "small mt-1")
}
func (b BootstrapDecorator) RootNode(n *html.Node) {
}
func (b BootstrapDecorator) RadioButton(n *html.Node, field formulate.StructField) {
b.validation(n, field)
}
func (b BootstrapDecorator) Fieldset(n *html.Node, field formulate.StructField) {
}
func (b BootstrapDecorator) Row(n *html.Node, field formulate.StructField) {
formulate.AppendClass(n, "row", "form-group")
}
func (b BootstrapDecorator) TextField(n *html.Node, field formulate.StructField) {
b.formControl(n)
b.validation(n, field)
}
func (b BootstrapDecorator) Label(n *html.Node, field formulate.StructField) {
b.col4(n)
}
func (b BootstrapDecorator) col4(n *html.Node) {
formulate.AppendClass(n, "col-md-4 col-12")
}
func (b BootstrapDecorator) col8(n *html.Node) {
formulate.AppendClass(n, "col-md-8 col-12")
}
func (b BootstrapDecorator) formControl(n *html.Node) {
formulate.AppendClass(n, "form-control")
}
func (b BootstrapDecorator) NumberField(n *html.Node, field formulate.StructField) {
b.formControl(n)
b.validation(n, field)
}
func (b BootstrapDecorator) CheckboxField(n *html.Node, field formulate.StructField) {
b.validation(n, field)
}
func (b BootstrapDecorator) TextareaField(n *html.Node, field formulate.StructField) {
b.formControl(n)
b.validation(n, field)
}
func (b BootstrapDecorator) TimeField(n *html.Node, field formulate.StructField) {
b.formControl(n)
b.validation(n, field)
}
func (b BootstrapDecorator) SelectField(n *html.Node, field formulate.StructField) {
b.formControl(n)
b.validation(n, field)
}
func (b BootstrapDecorator) ValidationText(n *html.Node, field formulate.StructField) {
if len(field.ValidationErrors) > 0 {
formulate.AppendClass(n, "invalid-feedback")
}
}
func (b BootstrapDecorator) validation(n *html.Node, field formulate.StructField) {
if len(field.ValidationErrors) == 0 {
return
}
formulate.AppendClass(n, "is-invalid")
}