From 53db709eb9df1d82b7eab26cf59041e342172678 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Tue, 13 Jan 2026 15:15:34 +0200 Subject: [PATCH] Bug 15349: Accept email addresses with display name in system preferences To test: 1. Before applying this patch, navigate to system preferences 2. Search for preference KohaAdminEmailAddress 3. Enter anything that is not in the format of valid "email@address.com" 4. Observe error "Please enter a valid email address." 5. Apply patch 6. Enter anything that is not in the format of valid "email@address.com" and not in the format of "display name " 7. Observe error "Please enter a valid email address (display name allowed)." 8. Enter email@address.com 9. Save all Administration preferences 10. Observe no errors 11. Enter Display Name 12. Save all Administration preferences 13. Observe no errors --- .../en/modules/admin/preferences/admin.pref | 2 +- .../prog/js/pages/preferences.js | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref index eac9b14907b..51b13021728 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref @@ -4,7 +4,7 @@ Administration: - - "Email address for the administrator of Koha: " - pref: KohaAdminEmailAddress - class: email + class: email-with-display-name - "(This is the default From: address for emails unless there is one for the particular library, and is referred to when an internal error occurs.)" - - "Email address to be set as the replyto in emails: " diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js index bbe128f2491..f23332c4053 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js @@ -365,12 +365,34 @@ $(".prefs-tab form").each(function () { }); }); +jQuery.validator.addMethod( + "email_with_display_name", + function (value, element) { + // Regex source + // https://web.archive.org/web/20251229171626/https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/email#basic_validation + // modified to accept "Display Name " + return ( + this.optional(element) || + /^(?:\w+\s+<[\w.!#$%&'*+/=?^`{|}~-]+@[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?(?:\.[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?)*>)$|^(?:[\w.!#$%&'*+/=?^`{|}~-]+@[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?(?:\.[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?)*)$/.test( + value + ) + ); + }, + __("Please enter a valid email address (display name allowed).") +); + $(".preference-email").each(function () { $(this).rules("add", { email: true, }); }); +$(".preference-email-with-display-name").each(function () { + $(this).rules("add", { + email_with_display_name: true, + }); +}); + $(".modalselect").on("click", function () { var datasource = $(this).data("source"); var exclusions = $(this).data("exclusions").split("|"); -- 2.34.1