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")),