shelves/backend/templates/form.go
2024-11-14 17:39:31 -05:00

40 lines
552 B
Go

package templates
import "html/template"
type Field struct {
Label string
Name string
Error string
Type string
Value string
Placeholder string
Valid bool
}
func (f *Field) init() {
if f.Type == "" {
f.Type = "text"
}
f.Valid = f.Valid || f.Error == ""
}
type Form struct {
Action string
Method string
Fields []Field
}
func (f Form) HTML() template.HTML {
if f.Method == "" {
f.Method = "POST"
}
for _, f := range f.Fields {
f.init()
}
return tmpls.renderHtml("form.tmpl.html", f)
}