|
@@ -10,13 +10,13 @@ import "strings"
|
10
|
10
|
type BasicForm struct {
|
11
|
11
|
formParams *FormParams
|
12
|
12
|
|
13
|
|
- autofillFields []string
|
14
|
|
- fields map[string]string
|
15
|
|
- errors map[string]string
|
|
13
|
+ prefillFields []string
|
|
14
|
+ fields map[string]string
|
|
15
|
+ errors map[string]string
|
16
|
16
|
}
|
17
|
17
|
|
18
|
|
-func (c *BasicForm) AutofillFields() []string {
|
19
|
|
- return c.autofillFields
|
|
18
|
+func (c *BasicForm) PrefillFields() []string {
|
|
19
|
+ return c.prefillFields
|
20
|
20
|
}
|
21
|
21
|
|
22
|
22
|
func (c *BasicForm) Fields() map[string]string {
|
|
@@ -32,8 +32,8 @@ func (c *BasicForm) FormParams() *FormParams {
|
32
|
32
|
|
33
|
33
|
}
|
34
|
34
|
|
35
|
|
-func (c *BasicForm) SetAutofillFields(autofillFields []string) {
|
36
|
|
- c.autofillFields = autofillFields
|
|
35
|
+func (c *BasicForm) SetPrefillFields(prefillFields []string) {
|
|
36
|
+ c.prefillFields = prefillFields
|
37
|
37
|
}
|
38
|
38
|
|
39
|
39
|
func (c *BasicForm) SetFields(fields map[string]string) {
|
|
@@ -57,7 +57,7 @@ func (c *BasicForm) ClearErrors() {
|
57
|
57
|
}
|
58
|
58
|
|
59
|
59
|
func (c *BasicForm) PopulateFields() {
|
60
|
|
- for _, fieldName := range c.autofillFields {
|
|
60
|
+ for _, fieldName := range c.prefillFields {
|
61
|
61
|
c.fields[fieldName] = FormValue(c.FormParams(), fieldName)
|
62
|
62
|
}
|
63
|
63
|
}
|
|
@@ -70,3 +70,16 @@ func (c *BasicForm) DisplayErrors() {
|
70
|
70
|
}
|
71
|
71
|
}
|
72
|
72
|
}
|
|
73
|
+
|
|
74
|
+func (c *BasicForm) RegenerateErrors() {
|
|
75
|
+
|
|
76
|
+ c.errors = make(map[string]string)
|
|
77
|
+
|
|
78
|
+ if OperatingEnvironment() == WebBrowserEnvironment && c.formParams.FormElement != nil {
|
|
79
|
+ errorSpans := c.formParams.FormElement.QuerySelectorAll(".formError")
|
|
80
|
+ for _, v := range errorSpans {
|
|
81
|
+ v.SetInnerHTML(c.errors[strings.Replace(v.GetAttribute("id"), "Error", "", -1)])
|
|
82
|
+ }
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+}
|