-
Notifications
You must be signed in to change notification settings - Fork 1
/
uiradiogroup.go
42 lines (37 loc) · 1.01 KB
/
uiradiogroup.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
package jaws
import (
"html/template"
"strings"
)
type RadioElement struct {
radio *Element
label *Element
nameAttr string
}
func (rq *Request) RadioGroup(nba *NamedBoolArray) (rl []RadioElement) {
nameAttr := `name="` + MakeID() + `"`
nba.ReadLocked(func(nbl []*NamedBool) {
for _, nb := range nbl {
rl = append(rl, RadioElement{
radio: rq.NewElement(NewUiRadio(nb)),
label: rq.NewElement(NewUiLabel(nb)),
nameAttr: nameAttr,
},
)
}
})
return
}
// Radio renders a HTML input element of type 'radio'.
func (r RadioElement) Radio(params ...interface{}) template.HTML {
var sb strings.Builder
r.radio.Render(&sb, append(params, r.nameAttr))
return template.HTML(sb.String()) // #nosec G203
}
// Label renders a HTML label element.
func (r *RadioElement) Label(params ...interface{}) template.HTML {
var sb strings.Builder
forAttr := string(r.radio.jid.AppendQuote([]byte("for=")))
r.label.Render(&sb, append(params, forAttr))
return template.HTML(sb.String()) // #nosec G203
}