From 84e121bb9c29fd04db1d1f23a3465d8ab1c00f3f Mon Sep 17 00:00:00 2001 From: Steve Cliff Date: Mon, 4 May 2026 22:16:59 +0100 Subject: [PATCH] fix: read 'name' across all per-kind sub-forms when editing channels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The channel form has three inputs all named 'name' (one per kind section: webhook / ntfy / smtp), but only the visible kind's input is filled in. PostForm.Get returns the first regardless of emptiness, so editing an ntfy or smtp channel always read '' from the (hidden, unfilled) webhook section's name input and rejected with 'name required'. Add firstNonEmpty helper that scans the slice for the first non-blank value. Same flavour of bug as the enabled checkbox fix in 6466f8c — both fall out of having multiple inputs share a name across the per-kind sub-forms. --- internal/server/http/ui_notifications.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/server/http/ui_notifications.go b/internal/server/http/ui_notifications.go index 3cfcb38..f409d3a 100644 --- a/internal/server/http/ui_notifications.go +++ b/internal/server/http/ui_notifications.go @@ -144,6 +144,20 @@ func (s *Server) decryptChannelConfig(ch store.NotificationChannel, dst any) err return json.Unmarshal(plain, dst) } +// firstNonEmpty returns the first non-empty (after TrimSpace) value in +// vals, or "". Used for fields like `name` that appear once per per-kind +// sub-form: only the visible kind's input is filled in, so PostForm.Get +// (which returns the first regardless of emptiness) would lose the +// actual value when the user edits the second or third kind. +func firstNonEmpty(vals []string) string { + for _, v := range vals { + if strings.TrimSpace(v) != "" { + return v + } + } + return "" +} + // formHasValue reports whether vals contains want. Used for hidden+checkbox // pairs (e.g. + ) // where r.PostForm.Get returns the first ("0") even when the checkbox is @@ -162,7 +176,7 @@ func formHasValue(vals []string, want string) bool { func formFromRequest(r *stdhttp.Request) *notificationForm { f := ¬ificationForm{ Kind: strings.TrimSpace(r.PostForm.Get("kind")), - Name: strings.TrimSpace(r.PostForm.Get("name")), + Name: strings.TrimSpace(firstNonEmpty(r.PostForm["name"])), Enabled: formHasValue(r.PostForm["enabled"], "1"), DefaultPriority: strings.TrimSpace(r.PostForm.Get("default_priority")),