From f0f531fa5c1911433c8730f3694a10d778ec50a2 Mon Sep 17 00:00:00 2001 From: jeremy breuillard Date: Thu, 7 Jul 2022 13:55:00 +0200 Subject: [PATCH] Bug 16786: Cannot add multiple emails adresses in an email field The primary email field can allow more than one email adresses if those are separated by comma (,;) Test plan: 1) Home > Patrons 2) Create a new patron / Edit an existing patron 3) Part:'Contact information' > Field:'Primary email' : write at least 2 email adresses separated by comma 4) Try to save it... impossible 5) Apply patch and repeat 1) to 3) then save again 6) Now this field allows more than one email adress as long as there is comma separation Signed-off-by: Kyle M Hall --- .../prog/en/includes/validator-strings.inc | 1 + koha-tmpl/intranet-tmpl/prog/js/members.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc index 0600f0a672b..b3177b112c3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc @@ -4,6 +4,7 @@ jQuery.extend(jQuery.validator.messages, { required: _("This field is required."), remote: _("Please fix this field."), + multimail: true, email: _("Please enter a valid email address."), url: _("Please enter a valid URL."), date: _("Please enter a valid date."), diff --git a/koha-tmpl/intranet-tmpl/prog/js/members.js b/koha-tmpl/intranet-tmpl/prog/js/members.js index 9ae9c18ba8d..1f1c9eccca9 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members.js +++ b/koha-tmpl/intranet-tmpl/prog/js/members.js @@ -235,10 +235,22 @@ $(document).ready(function(){ }, jQuery.validator.messages.phone); + $.validator.addMethod( + "multimail", + function(value, element, params) { + if ( value ) { + const emails = value.split(/[;,]+/); + return emails.every(email => jQuery.validator.methods.email.call(this, $.trim(email), element)) + } + return true + + }, jQuery.validator.messages.email); + $("#entryform").validate({ rules: { email: { - email: true + email: false, + multimail: true }, emailpro: { email: true -- 2.30.2