-
Notifications
You must be signed in to change notification settings - Fork 6
/
radioButton.go
60 lines (48 loc) · 1.15 KB
/
radioButton.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
package control
import (
"github.com/goradd/goradd/pkg/html"
"github.com/goradd/goradd/pkg/page"
)
type RadioButtonI interface {
CheckboxI
}
type RadioButton struct {
checkboxBase
group string
}
func NewRadioButton(parent page.ControlI, id string) *RadioButton {
c := &RadioButton{}
c.Init(c, parent, id)
return c
}
func (c *RadioButton) this() RadioButtonI {
return c.Self.(RadioButtonI)
}
func (c *RadioButton) DrawingAttributes() *html.Attributes {
a := c.checkboxBase.DrawingAttributes()
a.SetDataAttribute("grctl", "bs-radio")
a.Set("type", "radio")
if c.group == "" {
a.Set("name", c.ID()) // treat it like a checkbox if no group is specified
} else {
a.Set("name", c.group)
a.Set("value", c.ID())
}
return a
}
// UpdateFormValues is an internal call that lets us reflect the value of the checkbox on the web override
func (c *RadioButton) UpdateFormValues(ctx *page.Context) {
id := c.ID()
if v, ok := ctx.CheckableValue(id); ok {
c.SetCheckedNoRefresh(v)
}
}
func (c *RadioButton) SetGroup(g string) RadioButtonI {
c.group = g
c.Refresh()
return c.this()
}
func (c *RadioButton) Group() string {
return c.group
}
// TODO: Serialize