From 71c84c87b5bb486f37828e4fc5f78b7570616462 Mon Sep 17 00:00:00 2001 From: kurund Date: Thu, 4 Dec 2014 17:29:50 +0530 Subject: [PATCH] CRM-15684: onbehalf profile js break fixes ---------------------------------------- * CRM-15684: Onbehalf fails to set organizations information https://issues.civicrm.org/jira/browse/CRM-15684 --- CRM/Core/Page/AJAX/Location.php | 9 ++++----- .../CRM/Contribute/Form/Contribution/OnBehalfOf.tpl | 13 +++++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CRM/Core/Page/AJAX/Location.php b/CRM/Core/Page/AJAX/Location.php index a5b4002caf..c0aac0c533 100644 --- a/CRM/Core/Page/AJAX/Location.php +++ b/CRM/Core/Page/AJAX/Location.php @@ -157,17 +157,16 @@ class CRM_Core_Page_AJAX_Location { if (!empty($defaults)) { foreach ($profileFields as $key => $val) { - if (array_key_exists($key, $defaults)) { $htmlType = CRM_Utils_Array::value('html_type', $val); if ($htmlType == 'Radio') { - $elements["onbehalf[{$key}]"]['type'] = $htmlType; - $elements["onbehalf[{$key}]"]['value'] = $defaults[$key]; + $elements["onbehalf_{$key}"]['type'] = $htmlType; + $elements["onbehalf_{$key}"]['value'] = $defaults[$key]; } elseif ($htmlType == 'CheckBox') { + $elements["onbehalf_{$key}"]['type'] = $htmlType; foreach ($defaults[$key] as $k => $v) { - $elements["onbehalf[{$key}][{$k}]"]['type'] = $htmlType; - $elements["onbehalf[{$key}][{$k}]"]['value'] = $v; + $elements["onbehalf_{$key}"]['value'][$k] = $v; } } elseif ($htmlType == 'Multi-Select') { diff --git a/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl b/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl index 3fe53cd702..cd216b1a8a 100644 --- a/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl +++ b/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl @@ -227,12 +227,14 @@ function setLocationDetails(contactID , reset) { } if (data[ele].type == 'Radio') { if (data[ele].value) { - cj("input[name='"+ ele +"']").filter("[value=" + data[ele].value + "]").prop('checked', true); + var fldName = ele.replace('onbehalf_', ''); + cj("input[name='onbehalf["+ fldName +"]']").filter("[value='" + data[ele].value + "']").prop('checked', true); } } else if (data[ele].type == 'CheckBox') { - if (data[ele].value) { - cj("input[name='"+ ele +"']").prop('checked','checked'); + for (var selectedOption in data[ele].value) { + var fldName = ele.replace('onbehalf_', ''); + cj("input[name='onbehalf["+ fldName+"]["+ selectedOption +"]']").prop('checked','checked'); } } else if (data[ele].type == 'Multi-Select') { @@ -258,7 +260,10 @@ function setLocationDetails(contactID , reset) { } } else { - cj('#' + ele ).val(data[ele].value).change(); + // do not set defaults to file type fields + if (cj('#' + ele).attr('type') != 'file') { + cj('#' + ele ).val(data[ele].value).change(); + } } } }, -- 2.25.1