-
Notifications
You must be signed in to change notification settings - Fork 6
/
selectlist.go
152 lines (127 loc) · 3.78 KB
/
selectlist.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package panels
import (
"context"
. "github.com/goradd/goradd/pkg/bootstrap/control"
"github.com/goradd/goradd/pkg/bootstrap/examples"
"github.com/goradd/goradd/pkg/page"
"github.com/goradd/goradd/pkg/page/action"
"github.com/goradd/goradd/pkg/page/control"
"github.com/goradd/goradd/pkg/url"
"github.com/goradd/goradd/test/browsertest"
"strings"
)
type SelectListPanel struct {
control.Panel
}
func NewSelectListPanel(ctx context.Context, parent page.ControlI) {
p := &SelectListPanel{}
p.Self = p
p.Init(ctx, parent, "selectListPanel")
}
func (p *SelectListPanel) Init(ctx context.Context, parent page.ControlI, id string) {
itemList := []control.ListValue{
{"First", 1},
{"Second", 2},
{"Third", 3},
{"Fourth", 4},
{"Fifth", 5},
{"Sixth", 6},
{"Seventh", 7},
{"Eighth", 8},
}
p.Panel.Init(parent, id)
p.AddControls(ctx,
FormGroupCreator{
Label: "Standard SelectList",
Child: SelectListCreator{
ID: "singleSelectList",
NilItem: "- Select One -",
Items: itemList,
ControlOptions:page.ControlOptions{
IsRequired: true,
},
},
},
FormGroupCreator{
Label: "SelectList With Size",
Child: SelectListCreator{
ID: "selectListWithSize",
Items: itemList,
Size: 4,
ControlOptions:page.ControlOptions{
IsRequired: true,
},
},
},
FormFieldsetCreator{
Legend: "Radio List",
Instructions: "A radio list",
Child: RadioListCreator{
ID: "radioList1",
Items: itemList,
},
},
FormFieldsetCreator{
Legend: "Checkbox List",
Child: CheckboxListCreator{
ID: "checklist1",
Items: itemList,
},
},
ButtonCreator{
ID: "ajaxButton",
Text: "Submit Ajax",
OnSubmit: action.Ajax("selectListPanel", ButtonSubmit),
},
ButtonCreator{
ID: "serverButton",
Text: "Submit Server",
OnSubmit: action.Ajax("selectListPanel", ButtonSubmit),
},
)
}
func (p *SelectListPanel) Action(ctx context.Context, a page.ActionParams) {
switch a.ID {
case ButtonSubmit:
GetFormFieldset(p, "checklist1-fs").SetInstructions(
strings.Join(GetCheckboxList(p, "checklist1").SelectedIds(), ","))
}
}
func testSelectListAjaxSubmit(t *browsertest.TestForm) {
var myUrl = url.NewBuilder(controlsFormPath).SetValue("control", "lists").String()
t.LoadUrl(myUrl)
testSelectListSubmit(t, "ajaxButton")
t.Done("Complete")
}
func testSelectListServerSubmit(t *browsertest.TestForm) {
var myUrl = url.NewBuilder(controlsFormPath).SetValue("control", "lists").String()
t.LoadUrl(myUrl)
testSelectListSubmit(t, "serverButton")
t.Done("Complete")
}
// testSelectListSubmit does a variety of submits using the given button. We use this to double check the various
// results we might get after a submission, as well as ensure that the ajax and server submits produce
// the same results.
func testSelectListSubmit(t *browsertest.TestForm, btnID string) {
t.ChooseListValue("selectListWithSize", "2")
t.Click(btnID)
t.AssertEqual(true, t.ControlHasClass("singleSelectList-fg", "error"))
t.WithForm(func(f page.FormI) {
t.AssertEqual(2, GetSelectList(f, "selectListWithSize").IntValue())
})
t.ChooseListValue("singleSelectList", "1")
t.ChooseListValue("selectListWithSize", "2")
t.CheckGroup("radioList1", "3")
t.Click(btnID)
t.WithForm(func (f page.FormI) {
t.AssertEqual(1, GetSelectList(f, "singleSelectList").IntValue())
t.AssertEqual(2, GetSelectList(f, "selectListWithSize").IntValue())
t.AssertEqual(3, GetRadioList(f, "radioList1").IntValue())
})
}
func init() {
examples.RegisterPanel("lists", "Lists", NewSelectListPanel, 3)
page.RegisterControl(&SelectListPanel{})
browsertest.RegisterTestFunction("Bootstrap Select List Ajax Submit", testSelectListAjaxSubmit)
browsertest.RegisterTestFunction("Bootstrap Select List Server Submit", testSelectListServerSubmit)
}