From 840a24332850251cb2a47cf1452e9dee3df65f48 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Wed, 11 May 2016 12:00:01 +0100
Subject: [PATCH] Bug 16458: Update library when a guarantor is set
Content-Type: text/plain; charset=utf-8

If you edit a patron from the Edit link of the patron information block
(step 1 of the memberentry script), the branchcode is not displayed. If
you set a guarantor to a child from this form, a JavaScript error will
be raised:
  JavaScript error form.branchcode is undefined

It happens because there is the branchcode is not displayed and there is
no element with a branchcode name.

To avoid this issue, a branchcode hidden input is added to the form and
it will be updated when a guarantor is selected (same behavior as when
you edit a patron using the complete form).

Test plan:
Edit a patron using the Edit link of the patron info block (not the Edit
button in the toolbar)
Set a guarantor
=> Notice that the branchcode of the patron has been updated with the
branchcode of the guarantor

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
---
 .../intranet-tmpl/prog/en/modules/members/memberentrygen.tt      |    6 +++++-
 1 file changed, 5 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 aa1de3e..5abb6e4 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
@@ -289,7 +289,11 @@ $(document).ready(function() {
 	</fieldset>
 [% END # hide fieldset %]
 
-[% IF ( showguarantor ) %]<input type="hidden" id="guarantorid" name="guarantorid"   value="[% guarantorid %]" />
+[% IF ( showguarantor ) %]
+    <input type="hidden" id="guarantorid" name="guarantorid"   value="[% guarantorid %]" />
+    [% UNLESS step_6 %]
+        <input type="hidden" name="branchcode" value="[% branchcode %]" />
+    [% END %]
     <fieldset id="memberentry_guarantor" class="rows">
         <legend id="guarantor_lgd">Guarantor information</legend>
         <ol>
-- 
1.7.10.4