-
Notifications
You must be signed in to change notification settings - Fork 1
/
uiinputbool.go
53 lines (47 loc) · 1012 Bytes
/
uiinputbool.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
package jaws
import (
"io"
"strconv"
"github.com/linkdata/jaws/what"
)
type UiInputBool struct {
UiInput
BoolGetter
}
func (ui *UiInputBool) renderBoolInput(e *Element, w io.Writer, htmltype string, params ...interface{}) {
ui.parseGetter(e, ui.BoolGetter)
attrs := ui.parseParams(e, params)
v := ui.JawsGetBool(e)
ui.Last.Store(v)
if v {
attrs = append(attrs, "checked")
}
maybePanic(WriteHtmlInput(w, e.Jid(), htmltype, "", attrs...))
}
func (ui *UiInputBool) JawsUpdate(e *Element) {
v := ui.JawsGetBool(e)
if ui.Last.Swap(v) != v {
if v {
e.SetValue("true")
} else {
e.SetValue("false")
}
}
}
func (ui *UiInputBool) JawsEvent(e *Element, wht what.What, val string) (err error) {
if wht == what.Input {
var v bool
if val != "" {
if v, err = strconv.ParseBool(val); err != nil {
return
}
}
ui.Last.Store(v)
err = ui.BoolGetter.(BoolSetter).JawsSetBool(e, v)
e.Dirty(ui.Tag)
if err != nil {
return
}
}
return ui.UiHtml.JawsEvent(e, wht, val)
}