-
Notifications
You must be signed in to change notification settings - Fork 6
/
list_select.go
91 lines (77 loc) · 2.59 KB
/
list_select.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
package control
import (
"context"
"encoding/gob"
"github.com/goradd/goradd/pkg/bootstrap/config"
"github.com/goradd/goradd/pkg/html"
"github.com/goradd/goradd/pkg/page"
"github.com/goradd/goradd/pkg/page/control"
)
type SelectListI interface {
control.SelectListI
}
type SelectList struct {
control.SelectList
}
func NewSelectList(parent page.ControlI, id string) *SelectList {
t := new(SelectList)
t.Self = t
t.Init(parent, id)
return t
}
func (l *SelectList) Init(parent page.ControlI, id string) {
l.SelectList.Init(parent, id)
config.LoadBootstrap(l.ParentForm())
}
func (t *SelectList) DrawingAttributes(ctx context.Context) html.Attributes {
a := t.SelectList.DrawingAttributes(ctx)
a.AddClass("form-control")
return a
}
func init() {
gob.RegisterName("bootstrap.selectlist", new(SelectList))
}
type SelectListCreator struct {
ID string
// Items is a static list of labels and values that will be in the list. Or, use a DataProvider to dynamically generate the items.
Items []control.ListValue
// NilItem is a helper to add an item at the top of the list with a nil value. This is often
// used to specify no selection, or a message that a selection is required.
NilItem string
// DataProvider is the control that will dynamically provide the data for the list and that implements the DataBinder interface.
DataProvider control.DataBinder
// DataProviderID is the id of a control that will dynamically provide the data for the list and that implements the DataBinder interface.
DataProviderID string
// Size specifies how many items to show, and turns the list into a scrolling list
Size int
// Value is the initial value of the textbox. Often its best to load the value in a separate Load step after creating the control.
Value string
// SaveState saves the selected value so that it is restored if the form is returned to.
SaveState bool
page.ControlOptions
}
func (c SelectListCreator) Create(ctx context.Context, parent page.ControlI) page.ControlI {
ctrl := NewSelectList(parent, c.ID)
c.Init(ctx, ctrl)
return ctrl
}
func (c SelectListCreator) Init(ctx context.Context, ctrl SelectListI) {
sub := control.SelectListCreator{
ID: c.ID,
Items: c.Items,
NilItem: c.NilItem,
DataProvider: c.DataProvider,
Size: c.Size,
Value: c.Value,
SaveState: c.SaveState,
ControlOptions: c.ControlOptions,
}
sub.Init(ctx, ctrl)
}
// GetSelectList is a convenience method to return the control with the given id from the page.
func GetSelectList(c page.ControlI, id string) *SelectList {
return c.Page().GetControl(id).(*SelectList)
}
func init() {
page.RegisterControl(&SelectList{})
}