-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrender_theme_field.go
More file actions
40 lines (35 loc) · 1.32 KB
/
Copy pathrender_theme_field.go
File metadata and controls
40 lines (35 loc) · 1.32 KB
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
package form
import (
"html/template"
"github.com/donseba/go-form/v2/templates"
"github.com/donseba/go-form/v2/types"
)
// themeWrapIfGrouped wraps control HTML with the theme's input-group template when
// GroupBefore/GroupAfter is set.
func (f *Form) themeWrapIfGrouped(theme *templates.Theme, field types.FormField, control template.HTML) (template.HTML, error) {
if field.GroupBefore == "" && field.GroupAfter == "" {
return control, nil
}
return f.themeExec(theme, "input-group", map[string]any{
"GroupBefore": template.HTML(field.GroupBefore),
"GroupAfter": template.HTML(field.GroupAfter),
"Input": control,
}, nil)
}
// themeWrapField renders the wrapper template using the provided label and control HTML.
func (f *Form) themeWrapField(theme *templates.Theme, loc types.Localizer, field types.FormField, label template.HTML, control template.HTML, errorMap map[string][]string) (template.HTML, error) {
if field.InputType == types.InputFieldTypeHidden {
return control, nil
}
funcs := template.FuncMap{
"label": func() template.HTML { return label },
"field": func() template.HTML { return control },
"errors": func() []string {
if es, ok := errorMap[field.Name]; ok {
return es
}
return nil
},
}
return f.themeExec(theme, "wrapper", map[string]any{"Field": field, "Loc": loc}, funcs)
}