From 35523666df3d3a4a54ada70eedffeadbefd4e05f 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 a surname 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 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/js/members.js b/koha-tmpl/intranet-tmpl/prog/js/members.js index 2f58cb888c..8e6911a0cd 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members.js +++ b/koha-tmpl/intranet-tmpl/prog/js/members.js @@ -191,6 +191,22 @@ function write_age() { hint.html(age_string); } +function toggleRelationshipRequired() { + const relationshipField = $('.relationship'); + const label = relationshipField.parent().find('label'); + const requiredIndicator = relationshipField.parent().find('span.required'); + + if ($('#contactname').val().length === 0) { + 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(); @@ -221,6 +237,11 @@ $(document).ready(function(){ $(this).parents('fieldset').first().remove(); }); + if (mandatory_fields.includes('relationship')) { + toggleRelationshipRequired(); + $('#contactname').on('change', toggleRelationshipRequired); + } + $(document.body).on('change','.select_city',function(){ var selected_city = $(this).val(); var addressfield = $(this).data("addressfield"); -- 2.34.1