summaryrefslogtreecommitdiff
path: root/form/form.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--form/form.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/form/form.go b/form/form.go
new file mode 100644
index 0000000..84758f5
--- /dev/null
+++ b/form/form.go
@@ -0,0 +1,21 @@
+package form
+
+import (
+ "context"
+ "io"
+
+ "github.com/a-h/templ"
+)
+
+func Form(v any, errs []error) templ.Component {
+ fields := fields(v)
+ errors := fieldErrors(errs)
+ return templ.ComponentFunc(func(ctx context.Context, w io.Writer) error {
+ for _, field := range fields {
+ if err := field.item(errors[field.Name]).Render(ctx, w); err != nil {
+ return err
+ }
+ }
+ return nil
+ })
+}