-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkbox_slice.go
92 lines (79 loc) · 2.13 KB
/
checkbox_slice.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
package components
import (
"strconv"
mgc "github.com/mh-cbon/mdl-go-components"
base "github.com/mh-cbon/mdl-go-components/components_common"
)
type CheckboxSlice struct {
mgc.ViewComponent
base.Node
base.NodeType
base.NodeMutlipleValues
base.NodeWithOptions
base.NodeSingleError
InputClasses base.ClassList
InputAttr base.AttrList
ItemBlock string
}
func NewCheckboxSlice() *CheckboxSlice {
ret := &CheckboxSlice{}
ret.SetBlock("mgc/form_checkbox_slice")
ret.SetItemBlock("mgc/form_checkbox")
ret.SetType("checkbox")
return ret
}
func NewRadioSlice() *CheckboxSlice {
ret := NewCheckboxSlice()
ret.SetType("radio")
ret.SetItemBlock("mgc/form_radio")
return ret
}
func (view *CheckboxSlice) SetErrors(p base.ErrorProvider) {
err := p.GetError(view.GetName())
if err != nil {
view.SetError(err)
}
}
func (i *CheckboxSlice) SetItemBlock(s string) {
i.ItemBlock = s
}
func (i *CheckboxSlice) GetItemBlock() string {
return i.ItemBlock
}
func (view *CheckboxSlice) SetRipple(b bool) {
if b {
view.Classes.Add("mdl-js-ripple-effect")
} else {
view.Classes.Remove("mdl-js-ripple-effect")
}
}
func (view *CheckboxSlice) SetDisabled(b bool) {
if b {
view.InputAttr.Set("disabled", "disabled")
} else {
view.InputAttr.Remove("disabled")
}
}
func (view *CheckboxSlice) SetValue(s string) {
view.NodeWithOptions.SetValue(s)
}
func (view *CheckboxSlice) GetItem(index int, option base.NodeOption) *Checkbox {
sview := NewCheckbox()
sview.Attr.MergeFrom(view.Attr)
sview.Classes.MergeFrom(view.Classes)
sview.InputAttr.MergeFrom(view.InputAttr)
sview.InputClasses.MergeFrom(view.InputClasses)
sview.SetId(view.GetId() + "-" + strconv.Itoa(index))
sview.SetName(view.GetName())
sview.SetType(view.GetType())
sview.SetBlock(view.GetItemBlock())
sview.SetOption(option)
view.GetRenderContext().SetDefaultTo(sview)
return sview
}
func (view *CheckboxSlice) RenderItem(index int, option base.NodeOption, args ...interface{}) (string, error) {
return view.GetItem(index, option).Render(args)
}
func (view *CheckboxSlice) Render(args ...interface{}) (string, error) {
return view.GetRenderContext().RenderComponent(view, args)
}