From 22b5950af974869303ba0ecba10b449bac498a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=A4is=C3=A4?= Date: Thu, 7 Nov 2024 08:37:59 +0200 Subject: [PATCH] Bug 38373: check if mandatory relationship is needed for non-patron guarantor This patch checks if non-patron guarantor is added to the patron and changes the relationship to mandatory if needed. Test plan: 1) Add relationship as mandatory field 2) Add a child patron 3) See that the non-patron guarantor relationship is mandatory 4) Apply the patch 5) Add a child patron 6) See that the non-patron guarantor relationship is not mandatory 7) Fill surname or first name for the non-patron guarantor 8) See that the non-patron guarantor relationship turns mandatory Sponsored-by: Koha-Suomi Oy --- koha-tmpl/intranet-tmpl/prog/js/members.js | 32 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/members.js b/koha-tmpl/intranet-tmpl/prog/js/members.js index a20561cfe0..94ec2777e4 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members.js +++ b/koha-tmpl/intranet-tmpl/prog/js/members.js @@ -235,8 +235,24 @@ function write_age() { hint.html(age_string); } -$(document).ready(function () { - if ($("#yesdebarred").is(":checked")) { +function toggleRelationshipRequired() { + const relationshipField = $('.relationship'); + const label = relationshipField.parent().find('label'); + const requiredIndicator = relationshipField.parent().find('span.required'); + + if (!$('#contactname').val() && !$('#contactfirstname').val()) { + label.removeClass('required'); + requiredIndicator.hide(); + relationshipField.removeAttr('required'); + } else { + label.addClass('required'); + requiredIndicator.show(); + relationshipField.attr('required', 'required'); + } +} + +$(document).ready(function(){ + if($("#yesdebarred").is(":checked")){ $("#debarreduntil").show(); } else { $("#debarreduntil").hide(); @@ -274,7 +290,17 @@ $(document).ready(function () { } ); - $(document.body).on("change", ".select_city", function () { + if (mandatory_fields.includes('relationship')) { + toggleRelationshipRequired(); + if ($('#contactname').length) { + $('#contactname').on('change', toggleRelationshipRequired); + } + if ($('#contactfirstname').length) { + $('#contactfirstname').on('change', toggleRelationshipRequired); + } + } + + $(document.body).on('change','.select_city',function(){ var selected_city = $(this).val(); var addressfield = $(this).data("addressfield"); var myRegEx = new RegExp(/(.*)\|(.*)\|(.*)\|(.*)/); -- 2.34.1