From 32ce4269e41b0ba9ded2365bb5a38d2fe2b88755 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Mon, 25 Sep 2023 08:56:18 +0300 Subject: [PATCH 2/3] Bug 34671: Ignore new_guarantor_relationship and patron attribute inputs if they are 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. Also patron attributes not used by patron category are still present in form as hidden and marked as required if they are set as mandatory. This patch removes and adds attribute required to these fields based on their visibility. To test guarantor relationship: 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. To test patron attributes: 1. Add patron attribute for patron category A and set it as mandatory. 2. Add patron with category B and fill in required fields. 3. Attempt to save. => Error is displayed above "Additional attributes and identifiers" field set. 4. Apply this patch. 5. Repeat steps 2 and 3. => Save successfully. 6. Add new patron with category B, but this time change patrons category as A from patron form. => Confirm that mandatory patron attribute is displayed correctly and without it patron cannot be saved. Sponsored-by: Koha-Suomi Oy --- .../prog/en/modules/members/memberentrygen.tt | 22 +++++++++++++++++-- koha-tmpl/intranet-tmpl/prog/js/members.js | 5 +++++ 2 files changed, 25 insertions(+), 2 deletions(-) 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 361a178107..73e47f105d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -1521,13 +1521,21 @@ [% END %] [% FOREACH patron_attribute IN pa_loo.items %]
  • - [% IF patron_attribute.mandatory %] + [% IF patron_attribute.mandatory && patron_attribute.category_code == patron_category.categorycode%] + [% ELSIF patron_attribute.mandatory && patron_attribute.category_code != patron_category.categorycode %] + [% ELSE %] [% END %] [% IF ( patron_attribute.use_dropdown ) %] - + [% ELSIF patron_attribute.mandatory && patron_attribute.category_code != patron_category.categorycode %] + + [% END %] [% FOREACH auth_val_loo IN patron_attribute.auth_val_loop %] [% IF auth_val_loo.authorised_value == patron_attribute.value %] @@ -1951,6 +1959,16 @@ to_api_mapping = [% To.json(to_api_mapping) | $raw %]; [% END %] + //Remove attribute required so hidden new_guarantor_relationship is not validated + if($(".new_guarantor_relationship").is(":hidden")){ + $(".new_guarantor_relationship").removeAttr('required');; + } + + //Add attribute required so visible new_guarantor_relationship is validated + if($(".new_guarantor_relationship").is(":visible")){ + $(".new_guarantor_relationship").prop('required',true); + } + 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 8e7e9b6823..017191cd5c 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members.js +++ b/koha-tmpl/intranet-tmpl/prog/js/members.js @@ -158,6 +158,11 @@ function select_user(borrowernumber, borrower, relationship) { $("#guarantor_relationships").append(fieldset); fieldset.show(); + //Add attribute required so visible new_guarantor_relationship is validated + if($(".new_guarantor_relationship").is(":visible")){ + $(".new_guarantor_relationship").prop('required',true); + } + if (relationship) { fieldset.find(".new_guarantor_relationship").val(relationship); } -- 2.34.1