From 777ed3a851191fed5e146eba43b5149bbc9637d0 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Mon, 25 Sep 2023 08:56:18 +0300 Subject: [PATCH 2/2] 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 --- .../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 e97a15fdc6..55b976561f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -1932,6 +1932,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 ebff6fdb8d..db9615c2c0 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.34.1