fix(web): prefer form redirect and soft-default now_if_empty

Desk 文案 cancel links stamp redirect so POST leaves the compose page; empty date fields can opt into 空则现在 without blocking custom values.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-18 12:58:24 +08:00
1 parent 3f96592c99
commit 4b7643d833
5 files changed
+56 -9

No files matched your search

+13 -1
View File
@@ -69,6 +69,8 @@ func SetRules(formBag map[string]any, rules any) map[string]any {
}
// SetLabels stamps localized submit / cancel button copy (and optional cancel href).
// When cancelHref is set, also stamps redirect so successful POST lands on the list
// (or other cancel target) instead of the composing page's _mq_return path.
func SetLabels(formBag map[string]any, submit, cancel, cancelHref string) map[string]any {
out := cloneMap(formBag)
if s := strings.TrimSpace(submit); s != "" {
@@ -79,6 +81,7 @@ func SetLabels(formBag map[string]any, submit, cancel, cancelHref string) map[st
}
if s := strings.TrimSpace(cancelHref); s != "" {
out["cancel_href"] = s
out["redirect"] = s
}
return out
}
@@ -725,7 +728,16 @@ func RenderBodyCtx(formBag map[string]any, formID string, data, errors any, csrf
if csrf != "" {
fmt.Fprintf(&body, `<input type="hidden" name="_csrf" value="%s"/>`, esc(csrf))
}
if action == "update" && rowID != "" {
hasIDField := false
for _, f := range fields {
if fm, ok := f.(map[string]any); ok {
if strOf(fm, "name", "") == "id" && IsClientSource(strOf(fm, "source", "client")) {
hasIDField = true
break
}
}
}
if action == "update" && rowID != "" && !hasIDField {
fmt.Fprintf(&body, `<input type="hidden" name="id" value="%s"/>`, esc(rowID))
}
if ctx != nil {