From 69df95dabc0f83b8c0c43947fd3ad67d386324fe Mon Sep 17 00:00:00 2001 From: William Petit Date: Sat, 22 Feb 2025 15:32:10 +0100 Subject: [PATCH] feat: save latest summary in session storage to prevent loss of input --- .../webui/common/component/field.templ | 25 ++++++++- .../webui/common/component/field_templ.go | 51 +++++++++++++------ .../webui/issue/component/issue_page.templ | 24 ++++++++- .../webui/issue/component/issue_page_templ.go | 9 +++- 4 files changed, 89 insertions(+), 20 deletions(-) diff --git a/internal/http/handler/webui/common/component/field.templ b/internal/http/handler/webui/common/component/field.templ index 720d47b..9e4383a 100644 --- a/internal/http/handler/webui/common/component/field.templ +++ b/internal/http/handler/webui/common/component/field.templ @@ -21,7 +21,28 @@ templ FormField(form *form.Form, id string, name string, label string) { } } -templ FormTextarea(form *form.Form, id string, name string, label string) { +type FormTextareaOptions struct { + Attrs map[string]any +} + +type FormTextareaOptionFunc func(opts *FormTextareaOptions) + +func WithTextareaAttrs(kvAttrs ...any) FormTextareaOptionFunc { + return func(opts *FormTextareaOptions) { + opts.Attrs = keyValuesToAttrs(kvAttrs) + } +} + +func newFormTextareaOptions(funcs ...FormTextareaOptionFunc) *FormTextareaOptions { + opts := &FormTextareaOptions{} + for _, fn := range funcs { + fn(opts) + } + return opts +} + +templ FormTextarea(form *form.Form, id string, name string, label string, funcs ...FormTextareaOptionFunc) { + {{ opts := newFormTextareaOptions(funcs...) }} {{ field := form.Field(name) }} if field != nil {
@@ -29,7 +50,7 @@ templ FormTextarea(form *form.Form, id string, name string, label string) {
{{ err, hasErr := form.Error(name) }} {{ value, hasValue := field.Get("value") }} -