From 77b9736d044fddee583b67e9b8d650f2681e22f8 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 | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/js/members.js b/koha-tmpl/intranet-tmpl/prog/js/members.js index 2f58cb888c..acab7e760a 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() && !$('#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(); @@ -221,6 +237,16 @@ $(document).ready(function(){ $(this).parents('fieldset').first().remove(); }); + 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"); -- 2.34.1