-
Notifications
You must be signed in to change notification settings - Fork 6
/
fieldset.go
62 lines (52 loc) · 1.4 KB
/
fieldset.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
package control
import (
"context"
"github.com/goradd/goradd/pkg/html"
"github.com/goradd/goradd/pkg/page"
)
type FieldsetI interface {
PanelI
}
// Fieldset is a Panel that is drawn with a fieldset tag. The panel's label is used as the legend tag.
// Fieldset's cannot have wrappers.
type Fieldset struct {
Panel
}
// NewFieldset creates a new Fieldset.
func NewFieldset(parent page.ControlI, id string) *Fieldset {
p := &Fieldset{}
p.Init(p, parent, id)
return p
}
// Init is called by subclasses of Fieldset.
func (c *Fieldset) Init (self FieldsetI, parent page.ControlI, id string) {
c.Panel.Init(self, parent, id)
c.Tag = "fieldset"
}
func (c *Fieldset) this() FieldsetI {
return c.Self.(FieldsetI)
}
// ΩDrawingAttributes is called by the framework.
func (c *Fieldset) ΩDrawingAttributes() *html.Attributes {
a := c.Control.ΩDrawingAttributes()
a.SetDataAttribute("grctl", "fieldset")
return a
}
// ΩDrawTag is called by the framework.
func (c *Fieldset) ΩDrawTag(ctx context.Context) string {
var ctrl string
attributes := c.this().ΩDrawingAttributes()
if c.HasWrapper() {
panic("Fieldsets cannot have wrappers.")
}
buf := page.GetBuffer()
defer page.PutBuffer(buf)
if l := c.Label(); l != "" {
ctrl = html.RenderTag("legend", nil, l)
}
if err := c.this().ΩDrawInnerHtml(ctx, buf); err != nil {
panic(err)
}
ctrl = html.RenderTag(c.Tag, attributes, ctrl+buf.String())
return ctrl
}