shelves/backend/templates/form.go
2024-11-15 15:05:06 -05:00

42 lines
558 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 i := range f.Fields {
f.Fields[i].init()
}
return Tmpls.HTML("form.tmpl.html", f)
}