From 45bc180a15d1edf3a20f25c4bb428819b94e6ad9 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 3 Jul 2023 14:04:50 +0800 Subject: [PATCH] Make "cancel" buttons have proper type in modal forms (#25618) Replace #25446, fix #25438 All "cancel" buttons which do not have "type" should not submit the form, should not be triggered by "Enter". This is a complete fix for all modal dialogs. The major change is "modules/aria/modal.js", "devtest" related code is for demo/test purpose. --- routers/web/devtest/devtest.go | 12 +++++++++++- templates/devtest/fomantic-modal.tmpl | 13 +++++++++++++ web_src/js/modules/aria/modal.js | 26 ++++++++++++++++++++++++++ web_src/js/modules/fomantic.js | 2 ++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 web_src/js/modules/aria/modal.js diff --git a/routers/web/devtest/devtest.go b/routers/web/devtest/devtest.go index 64b732c035..525ca9be53 100644 --- a/routers/web/devtest/devtest.go +++ b/routers/web/devtest/devtest.go @@ -34,7 +34,7 @@ func List(ctx *context.Context) { func FetchActionTest(ctx *context.Context) { _ = ctx.Req.ParseForm() - ctx.Flash.Info(ctx.Req.Method + " " + ctx.Req.RequestURI + "
" + + ctx.Flash.Info("fetch-action: " + ctx.Req.Method + " " + ctx.Req.RequestURI + "
" + "Form: " + ctx.Req.Form.Encode() + "
" + "PostForm: " + ctx.Req.PostForm.Encode(), ) @@ -52,5 +52,15 @@ func Tmpl(ctx *context.Context) { ctx.Data["TimePast1y"] = now.Add(-1 * 366 * 86400 * time.Second) ctx.Data["TimeFuture1y"] = now.Add(1 * 366 * 86400 * time.Second) + if ctx.Req.Method == "POST" { + _ = ctx.Req.ParseForm() + ctx.Flash.Info("form: "+ctx.Req.Method+" "+ctx.Req.RequestURI+"
"+ + "Form: "+ctx.Req.Form.Encode()+"
"+ + "PostForm: "+ctx.Req.PostForm.Encode(), + true, + ) + time.Sleep(2 * time.Second) + } + ctx.HTML(http.StatusOK, base.TplName("devtest"+path.Clean("/"+ctx.Params("sub")))) } diff --git a/templates/devtest/fomantic-modal.tmpl b/templates/devtest/fomantic-modal.tmpl index aaa4c2c12d..799bab7594 100644 --- a/templates/devtest/fomantic-modal.tmpl +++ b/templates/devtest/fomantic-modal.tmpl @@ -1,5 +1,18 @@ {{template "base/head" .}}
+ {{template "base/alert" .}} + + + + +
+