-
Notifications
You must be signed in to change notification settings - Fork 1
/
radio.go
36 lines (31 loc) · 876 Bytes
/
radio.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
package jaws
import "html/template"
type Radio struct {
nba *NamedBoolArray
rq *Request
fn InputTextFn
NamedBool
}
// Jid returns the JaWS ID.
func (r *Radio) Jid() string {
return r.nba.JidOf(r.Name)
}
// Radio renders a HTML input element of type 'radio'.
func (r *Radio) Radio(attrs ...string) template.HTML {
jid := r.Jid()
attrs = append(attrs, `name="`+r.nba.Jid+`"`)
attrs = append(attrs, `id="`+jid+`"`)
if r.Checked {
attrs = append(attrs, `checked`)
}
r.rq.RegisterEventFn(jid, func(rq *Request, id, evt, val string) error {
return r.nba.radioEventFn(rq, id, evt, val, r.fn)
})
return HtmlInput(jid, "radio", "", attrs...)
}
// Label renders a HTML label element.
func (r *Radio) Label(attrs ...string) template.HTML {
jid := r.nba.JidOf(r.Name)
attrs = append(attrs, `for="`+jid+`"`)
return HtmlInner("", "label", "", r.Html, attrs...)
}