From 2dc6f15eca007105fb6c3972265e6da53696bdf1 Mon Sep 17 00:00:00 2001 From: Gerben Date: Fri, 23 Mar 2018 15:10:42 +0100 Subject: [PATCH] Don't warn users about *every* dirty form (#3707) The choice regarding which forms should or should not trigger a warning is subjective. I tried to be consistent and not warn about forms that: - run an action, rather than edit data: search, send an email. - delete data: a warning about losing data would be confusing Note that forms on sign-in pages were already ignored (using a selector, rather than an explicit class on the form element). Fixes #3698. --- public/js/index.js | 7 +++++-- templates/admin/base/search.tmpl | 2 +- templates/admin/config.tmpl | 2 +- templates/explore/code.tmpl | 2 +- templates/explore/search.tmpl | 2 +- templates/org/settings/delete.tmpl | 2 +- templates/repo/commits_table.tmpl | 2 +- templates/repo/home.tmpl | 2 +- templates/repo/issue/search.tmpl | 2 +- templates/repo/search.tmpl | 2 +- templates/user/auth/activate.tmpl | 2 +- templates/user/auth/forgot_passwd.tmpl | 2 +- templates/user/auth/reset_passwd.tmpl | 2 +- templates/user/settings/applications.tmpl | 2 +- templates/user/settings/delete.tmpl | 2 +- 15 files changed, 19 insertions(+), 16 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index 1e795a5044..8b3d7c3d7d 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1663,8 +1663,11 @@ function selectRange($list, $select, $from) { } $(function () { - if ($('.user.signin').length > 0) return; - $('form').areYouSure(); + // Warn users that try to leave a page after entering data into a form. + // Except on sign-in pages, and for forms marked as 'ignore-dirty'. + if ($('.user.signin').length === 0) { + $('form:not(.ignore-dirty)').areYouSure(); + } // Parse SSH Key $("#ssh-key-content").on('change paste keyup',function(){ diff --git a/templates/admin/base/search.tmpl b/templates/admin/base/search.tmpl index 749e42af2d..7d23e51c89 100644 --- a/templates/admin/base/search.tmpl +++ b/templates/admin/base/search.tmpl @@ -17,7 +17,7 @@ -
+
diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl index fd9f4f3303..7c353ad301 100644 --- a/templates/admin/config.tmpl +++ b/templates/admin/config.tmpl @@ -185,7 +185,7 @@ {{end}}
{{.i18n.Tr "admin.config.mailer_user"}}
{{if .Mailer.User}}{{.Mailer.User}}{{else}}(empty){{end}}

- + {{.CsrfTokenHtml}}
diff --git a/templates/explore/code.tmpl b/templates/explore/code.tmpl index 6003486213..742ed59442 100644 --- a/templates/explore/code.tmpl +++ b/templates/explore/code.tmpl @@ -2,7 +2,7 @@
{{template "explore/navbar" .}}
- +
diff --git a/templates/explore/search.tmpl b/templates/explore/search.tmpl index 6f37bcb236..906dd06caf 100644 --- a/templates/explore/search.tmpl +++ b/templates/explore/search.tmpl @@ -15,7 +15,7 @@
- +
diff --git a/templates/org/settings/delete.tmpl b/templates/org/settings/delete.tmpl index dc1858e5c4..3b0ee09b17 100644 --- a/templates/org/settings/delete.tmpl +++ b/templates/org/settings/delete.tmpl @@ -13,7 +13,7 @@

{{.i18n.Tr "org.settings.delete_prompt" | Str2html}}

- + {{.CsrfTokenHtml}}
diff --git a/templates/repo/commits_table.tmpl b/templates/repo/commits_table.tmpl index 4503976e0e..8a8e2c369e 100644 --- a/templates/repo/commits_table.tmpl +++ b/templates/repo/commits_table.tmpl @@ -5,7 +5,7 @@
{{if .PageIsCommits}} - + diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 91db56c98f..9f705c967c 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -10,7 +10,7 @@
{{if .RepoSearchEnabled}}