forked from bluele/gforms
-
Notifications
You must be signed in to change notification settings - Fork 1
/
multipletextfield.go
58 lines (50 loc) · 1.2 KB
/
multipletextfield.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
package gforms
import (
"reflect"
)
// It maps value to FormInstance.CleanedData as type `[]string`.
type MultipleTextField struct {
BaseField
}
// Create a new MultipleField instance.
func (f *MultipleTextField) New() FieldInterface {
fi := new(MultipleTextFieldInstance)
fi.Model = f
fi.V = nilV("")
return fi
}
// Instance for MultipleTextField.
type MultipleTextFieldInstance struct {
FieldInstance
}
// Create a new MultipleTextField with validators and widgets.
func NewMultipleTextField(name string, vs Validators, ws ...Widget) *MultipleTextField {
f := new(MultipleTextField)
f.name = name
f.validators = vs
if len(ws) > 0 {
f.widget = ws[0]
} else {
f.widget = SelectMultipleWidget(map[string]string{}, nil)
}
return f
}
// Get a value from request data, and clean it as type `[]string`.
func (f *MultipleTextFieldInstance) Clean(data Data) error {
m, hasField := data[f.Model.GetName()]
if hasField {
f.V = m
m.Kind = reflect.Slice
m.Value = m.rawValueAsStringArray()
m.IsNil = false
return nil
}
return nil
}
func (f *MultipleTextFieldInstance) html() string {
return ""
}
// Get as HTML format.
func (f *MultipleTextFieldInstance) Html() string {
return fieldToHtml(f)
}