-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.go
138 lines (120 loc) · 3.4 KB
/
input.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package objhtml
import (
"fmt"
//"golang.org/x/net/html"
)
//=============================================
// <input> Input elements //
//=============================================
//=============================================
// <input> Text Input //
//=============================================
// Input types
const (
InputButton = "button"
InputCheckbox = "checkbox"
InputColor = "color"
InputDate = "date"
InputDatetime = "datetime"
InputDatetimeLocal = "datetime-local"
InputEmail = "email"
InputFile = "file"
InputHidden = "hidden"
InputImage = "image"
InputMonth = "month"
InputNumber = "number"
InputPassword = "password"
InputRadio = "radio"
InputRange = "range"
InputReset = "reset"
InputSearch = "search"
InputSubmit = "submit"
InputTel = "tel"
InputText = "text"
InputTime = "time"
InputUrl = "url"
InputWeek = "week"
)
//Checkbox represents a checkbox with label
type Input struct {
*Element
value *Element
}
//NewTextInput creates a new "text" input
func NewInput(typeinput string) *Input {
i := new(Input)
i.Element = NewElement("input")
i.SetAttribute("type", typeinput)
return i
}
//NewTextInput creates a new "text" input
func NewTextInput(value string) *Element {
input := NewElement("input")
input.SetAttribute("type", "text")
if value != "" {
input.SetAttribute("value", value)
}
return input
}
//=============================================
// <input> Checkbox Input //
//=============================================
//Checkbox represents a checkbox with label
type CheckBoxInput struct {
*Element
chkbox *Element
text *Element
}
//NewCheckBox creates a bootstrap checkbox with label
func NewCheckBoxInput(caption string, checked bool) *CheckBoxInput {
cb := new(CheckBoxInput)
cb.Element = NewElement("label")
cb.chkbox = NewElement("input")
cb.chkbox.SetAttribute("type", "checkbox")
if checked {
cb.chkbox.SetAttribute("checked", "")
}
cb.text = NewText(caption)
cb.Element.AddElement(cb.chkbox)
cb.Element.AddElement(cb.text)
cb.Element.SetAttribute("for", cb.chkbox.GetID())
return cb
}
//Checked is true if the checkbox is checked
func (cb *CheckBoxInput) Checked() bool {
_, exists := cb.chkbox.GetAttribute("checked")
return exists
}
//=============================================
// <input> File Input //
//=============================================
//FileButton is an file-input linked to a button
type FileInput struct {
*Element
btn *Element
input *Element
}
//NewFileButton creates new 'file' input with a button
func NewFileInput(buttontype string, caption string, foldersOnly bool) *FileInput {
fb := new(FileInput)
//fb.Element = wgui.NewElement("div")
fb.btn = NewButton(buttontype, caption)
fb.input = NewElement("input")
fb.input.SetAttribute("type", "file")
fb.input.SetAttribute("style", "display:none;")
if foldersOnly {
fb.input.SetAttribute("nwdirectory", "")
}
fb.btn.SetAttribute(OnClick, fmt.Sprintf("%s.click()", fb.input.GetID()))
fb.AddElement(fb.input)
fb.AddElement(fb.btn)
return fb
}
////OnChange registers the onchange event
//func (fb *FileInput) OnChange(handler.EventHandler) {
// fb.input.OnEvent(OnChange, handler)
//}
//GetValue returns the selected file value
func (fb *FileInput) GetValue() string {
return fb.input.GetValue()
}