-
Notifications
You must be signed in to change notification settings - Fork 1
/
uiinputdate.go
48 lines (41 loc) · 1004 Bytes
/
uiinputdate.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"
"time"
"github.com/linkdata/jaws/what"
)
type UiInputDate struct {
UiInput
TimeSetter
}
func (ui *UiInputDate) str() string {
return ui.Last.Load().(time.Time).Format(ISO8601)
}
func (ui *UiInputDate) renderDateInput(e *Element, w io.Writer, jid Jid, htmltype string, params ...interface{}) error {
ui.parseGetter(e, ui.TimeSetter)
attrs := e.ParseParams(params)
ui.Last.Store(ui.JawsGetTime(e))
return WriteHtmlInput(w, e.Jid(), htmltype, ui.str(), attrs)
}
func (ui *UiInputDate) JawsUpdate(e *Element) {
if t := ui.JawsGetTime(e); ui.Last.Swap(t) != t {
e.SetValue(ui.str())
}
}
func (ui *UiInputDate) JawsEvent(e *Element, wht what.What, val string) (err error) {
if wht == what.Input {
var v time.Time
if val != "" {
if v, err = time.Parse(ISO8601, val); err != nil {
return
}
}
ui.Last.Store(v)
err = ui.TimeSetter.JawsSetTime(e, v)
e.Dirty(ui.Tag)
if err != nil {
return
}
}
return ui.UiHtml.JawsEvent(e, wht, val)
}