-
Notifications
You must be signed in to change notification settings - Fork 6
/
fieldset.tpl.go
executable file
·145 lines (105 loc) · 2.96 KB
/
fieldset.tpl.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//** This file was code generated by got. DO NOT EDIT. ***
package control
import (
"bytes"
"context"
"html"
grhtml "github.com/goradd/goradd/pkg/html"
"github.com/goradd/goradd/pkg/page"
)
// FieldsetTmpl is the template for special situations where you want to wrap a group of controls with a fieldset
// This is useful for groups of related controls, like a group of radio buttons.
// If you want the entire group to be a row, give the wrapper a "row" class. This will automatically pull out the
// row class and add an independent div wrapper with a row class, which is a special requirement for this kind of object.
func FieldsetTmpl(ctx context.Context, wrapper *FieldsetWrapperType, ctrl page.ControlI, h string, buf *bytes.Buffer) {
var hasInstructions bool = (ctrl.Instructions() != "")
var hasRow bool
ctrl.WrapperAttributes().AddClass("form-group")
if wrapper.UseTooltips {
// bootstrap requires that parent of a tooltipped object has position relative
ctrl.WrapperAttributes().SetStyle("position", "relative")
}
if ctrl.WrapperAttributes().HasClass("row") {
ctrl.WrapperAttributes().RemoveClass("row")
hasRow = true
}
wrapper.LabelAttributes().AddClass("col-form-label").
AddClass("pt-0") // helps with alignment
buf.WriteString(`<fieldset id="`)
buf.WriteString(ctrl.ID())
buf.WriteString(`_ctl" `)
buf.WriteString(ctrl.WrapperAttributes().String())
buf.WriteString(` >
`)
if hasRow {
buf.WriteString(`<div class="row">`)
}
if ctrl.Label() != "" {
buf.WriteString(` <legend id="`)
buf.WriteString(ctrl.ID())
buf.WriteString(`_lbl" `)
buf.WriteString(wrapper.LabelAttributes().String())
buf.WriteString(`>`)
buf.WriteString(html.EscapeString(ctrl.Label()))
buf.WriteString(`</legend>
`)
}
buf.WriteString(`
`)
buf.WriteString(grhtml.Indent(h))
buf.WriteString(`
`)
msg := ctrl.ValidationMessage()
var class string
switch ctrl.ValidationState() {
case page.ValidationWaiting:
fallthrough // we need to correctly style
case page.ValidationValid:
if msg == "" {
msg = " "
} else {
msg = html.EscapeString(msg)
}
if wrapper.UseTooltips {
class = "valid-tooltip"
} else {
class = "valid-feedback"
}
case page.ValidationInvalid:
if msg == "" {
msg = " "
} else {
msg = html.EscapeString(msg)
}
if wrapper.UseTooltips {
class = "invalid-tooltip"
} else {
class = "invalid-feedback"
}
}
if hasInstructions {
buf.WriteString(`<small id="`)
buf.WriteString(ctrl.ID())
buf.WriteString(`_inst" class="form-text" >`)
buf.WriteString(html.EscapeString(ctrl.Instructions()))
buf.WriteString(`</small>`)
}
if ctrl.ValidationState() != page.ValidationNever {
buf.WriteString(`<div id="`)
buf.WriteString(ctrl.ID())
buf.WriteString(`_err" class="`)
buf.WriteString(class)
buf.WriteString(`">`)
buf.WriteString(msg)
buf.WriteString(`</div>`)
}
buf.WriteString(`
`)
if hasRow {
buf.WriteString(`</div>`)
}
buf.WriteString(`
</fieldset>
`)
return
}