-
Notifications
You must be signed in to change notification settings - Fork 1
/
radio.go
40 lines (34 loc) · 925 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
37
38
39
40
package jaws
import (
"html/template"
"github.com/linkdata/jaws/what"
)
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, wht what.What, id, val string) error {
return r.nba.radioEventFn(rq, wht, id, 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...)
}