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:
1 parent
3f96592c99
commit
4b7643d833
5 files changed
+56
-9
No files matched your search
@@ -18,6 +18,8 @@ func normalizeSource(raw string) string {
|
||||
return "session.username"
|
||||
case "now", "utc.now", "server.now", "时间", "utc":
|
||||
return "now"
|
||||
case "now_if_empty", "空则现在", "now?":
|
||||
return "now_if_empty"
|
||||
default:
|
||||
return s
|
||||
}
|
||||
@@ -25,7 +27,8 @@ func normalizeSource(raw string) string {
|
||||
|
||||
// IsClientSource reports whether the field is filled by the browser.
|
||||
func IsClientSource(source string) bool {
|
||||
return normalizeSource(source) == "client"
|
||||
src := normalizeSource(source)
|
||||
return src == "client" || src == "now_if_empty"
|
||||
}
|
||||
|
||||
// RequestContext carries session user and route params for form source stamping
|
||||
@@ -39,7 +42,8 @@ type RequestContext struct {
|
||||
}
|
||||
|
||||
// ApplySources strips client-supplied values for non-client fields, then stamps
|
||||
// from ctx. Always overwrites server-owned keys.
|
||||
// from ctx. Always overwrites server-owned keys. `now_if_empty` keeps a non-empty
|
||||
// client value and only stamps UTC now when the field was left blank.
|
||||
func ApplySources(formBag map[string]any, data map[string]any, ctx *RequestContext) {
|
||||
if data == nil {
|
||||
return
|
||||
@@ -57,12 +61,21 @@ func ApplySources(formBag map[string]any, data map[string]any, ctx *RequestConte
|
||||
continue
|
||||
}
|
||||
src := normalizeSource(strOf(fm, "source", "client"))
|
||||
if src == "client" {
|
||||
switch src {
|
||||
case "client":
|
||||
continue
|
||||
}
|
||||
delete(data, name)
|
||||
if v, ok := resolveSource(src, ctx); ok {
|
||||
data[name] = v
|
||||
case "now_if_empty":
|
||||
if data[name] != nil && strings.TrimSpace(cellStr(data[name])) != "" {
|
||||
continue
|
||||
}
|
||||
if v, ok := resolveSource("now", ctx); ok {
|
||||
data[name] = v
|
||||
}
|
||||
default:
|
||||
delete(data, name)
|
||||
if v, ok := resolveSource(src, ctx); ok {
|
||||
data[name] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user