From b2447bc967df37b31282a97e32c581954bb8bcc9 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Thu, 17 Oct 2024 16:37:23 +0200 Subject: Move from html/template to templ --- form/form.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 form/form.go (limited to 'form/form.go') 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 + }) +} -- cgit v1.2.3-70-g09d2