From 73af178c6f147839152ac70b7c467cd24ed86158 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Mon, 25 Sep 2023 08:56:18 +0300 Subject: [PATCH] Bug 34671: Ignore new_guarantor_relationship input if it's hidden Validating patron forms hidden fields causes problems when adding/modifying guarantee patrons since class new_guarantor_relationship is always hidden and mandatory if syspref "borrowerRelationship" is set. This patch adds class ignore_validation to relationship input if it's hidden to ignore validatation and removes it when input is displayed, so it is validated. To test: 1. Apply previous patch. 2. Add or modify guarantee patron. 3. Do not add or modify guarantor. 4. Attempt to save patron. => Pressing save button does nothing and no error is displayed. 5. Apply this patch. 6. Again add or modify guarantee patron and don't add or modify guarantor. 7. Attempt to save. => Saving should now be successfull. 8. Again, add or modify guarantee patron, but this time also add or modify guarantor. 9. Leave relationship input empty. 10. Attempt to save. => Saving should fail and error "There are some required fields missing..." should be displayed on top of "Patron guarantor" field set. 11. Add relationship for guarantor and save. => Saving should now be successfull. Sponsored-by: Koha-Suomi Oy Signed-off-by: Kelly --- .../prog/en/modules/members/memberentrygen.tt | 10 ++++++++++ koha-tmpl/intranet-tmpl/prog/js/members.js | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index 007e101206..7837d99efe 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -1954,6 +1954,16 @@ legend:hover { [% END %] $("#guarantor_template").hide(); + //Add class ignore_validation to hidden new_guarantor_relationship to ignore it when form is validated + if($(".new_guarantor_relationship").is(":hidden")){ + $(".new_guarantor_relationship").addClass("ignore_validation"); + } + + // Remove class ignore_validation from new_guarantor_relationship to validate missing relationship value + if($(".new_guarantor_relationship").is(":visible")){ + $(".new_guarantor_relationship").removeClass("ignore_validation"); + } + var TalkingTechItivaPhoneNotification = [% Koha.Preference('TalkingTechItivaPhoneNotification') || 0 | html %]; var PhoneNotification = [% Koha.Preference('PhoneNotification') || 0 | html %]; diff --git a/koha-tmpl/intranet-tmpl/prog/js/members.js b/koha-tmpl/intranet-tmpl/prog/js/members.js index dbdf7c1790..f49f11243f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members.js +++ b/koha-tmpl/intranet-tmpl/prog/js/members.js @@ -118,6 +118,11 @@ function select_user(borrowernumber, borrower, relationship) { $('#guarantor_relationships').append( fieldset ); fieldset.show(); + // Remove class ignore_validation from new_guarantor_relationship to validate missing relationship value + if($(".new_guarantor_relationship").is(":visible")){ + $(".new_guarantor_relationship").removeClass("ignore_validation"); + } + if ( relationship ) { fieldset.find('.new_guarantor_relationship').val(relationship); } @@ -240,7 +245,7 @@ $(document).ready(function(){ jQuery.validator.messages.phone); $("#entryform").validate({ - ignore: "", + ignore: ".ignore_validation", rules: { email: { email: true -- 2.30.2