From 96f1c3900a748808f3db65fe36c6998c377442c7 Mon Sep 17 00:00:00 2001 From: Maryse Simard Date: Tue, 5 Feb 2019 18:26:42 -0500 Subject: [PATCH] Bug 8000: (QA follow-up) Add email validation to system preferences Content-Type: text/plain; charset=utf-8 This patch uses the JQuery validator plugin to add validation to preferences of class email in the system preferences page. A field containing an invalid value (even if not modified) should prevent saving. To test, confirm that when entering an invalid email address in the SendAllEmailsTo field, an error message appears and saving is prevented. Correcting the value should hide the message and let you save as normal. Signed-off-by: Liz Rea Signed-off-by: Marcel de Rooy --- .../prog/en/modules/admin/preferences.tt | 1 + .../intranet-tmpl/prog/js/pages/preferences.js | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt index 54d27fee9a..764f1645d9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt @@ -211,6 +211,7 @@ var MSG_LOADING = _( "Loading..." ); var MSG_ALL_VALUE_WARN = _("Note: _ALL_ value will override all other values"); var MSG_UPD_LOC_FORMAT_WARN = _("The following values are not formatted correctly:"); + var MSG_INVALID = _( "Error: presence of invalid data prevent saving. Please make the corrections and try again." ); [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %] [% Asset.js("js/ajax.js") | $raw %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js index 0fa0238133..d5db030e7b 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js @@ -3,6 +3,11 @@ KOHA.Preferences = { Save: function ( form ) { + if ( ! $(form).valid() ) { + humanMsg.displayAlert( MSG_INVALID ); + return; + } + modified_prefs = $( form ).find( '.modified' ); // $.serialize removes empty value, we need to keep them. // If a multiple select has all its entries unselected @@ -181,4 +186,23 @@ $( document ).ready( function () { if ( alert_text.length ) alert(alert_text); }); + $(".prefs-tab form").each(function () { + $(this).validate({ + rules: { }, + errorPlacement: function(error, element) { + var placement = $(element).parent(); + if (placement) { + $(placement).append(error) + } else { + error.insertAfter(element); + } + } + }); + }); + + $(".preference-email").each(function() { + $(this).rules("add", { + email: true + }); + }); } ); -- 2.11.0