From 24b73176eec956a1eea8e78ea34743502bf41235 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 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. --- .../prog/en/modules/admin/preferences.tt | 1 + .../intranet-tmpl/prog/js/pages/preferences.js | 25 ++++++++++++++++++++++ 2 files changed, 26 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 4d24de3..2c87f64 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt @@ -197,6 +197,7 @@ var MSG_SESSION_TIMED_OUT = _( "You need to log in again, your session has timed out" ); var MSG_DATA_NOT_SAVED = _( "Error; your data might not have been saved" ); var MSG_LOADING = _( "Loading..." ); + 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 f7ed5e1..8b593ec 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js @@ -2,6 +2,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 @@ -143,4 +148,24 @@ $( document ).ready( function () { if ( search_jumped ) { document.location.hash = "jumped"; } + + $(".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.7.4