-
Notifications
You must be signed in to change notification settings - Fork 1
/
uiinputfloat.go
48 lines (41 loc) · 1.01 KB
/
uiinputfloat.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
package jaws
import (
"io"
"strconv"
"github.com/linkdata/jaws/what"
)
type UiInputFloat struct {
UiInput
FloatSetter
}
func (ui *UiInputFloat) str() string {
return strconv.FormatFloat(ui.Last.Load().(float64), 'f', -1, 64)
}
func (ui *UiInputFloat) renderFloatInput(e *Element, w io.Writer, htmltype string, params ...interface{}) error {
ui.parseGetter(e, ui.FloatSetter)
attrs := ui.parseParams(e, params)
ui.Last.Store(ui.JawsGetFloat(e))
return WriteHtmlInput(w, e.Jid(), htmltype, ui.str(), attrs...)
}
func (ui *UiInputFloat) JawsUpdate(e *Element) {
if f := ui.JawsGetFloat(e); ui.Last.Swap(f) != f {
e.SetValue(ui.str())
}
}
func (ui *UiInputFloat) JawsEvent(e *Element, wht what.What, val string) (err error) {
if wht == what.Input {
var v float64
if val != "" {
if v, err = strconv.ParseFloat(val, 64); err != nil {
return
}
}
ui.Last.Store(v)
err = ui.FloatSetter.JawsSetFloat(e, v)
e.Dirty(ui.Tag)
if err != nil {
return
}
}
return ui.UiHtml.JawsEvent(e, wht, val)
}