From 9c3a8754225eb8b0decc0b6ec0ae8435c6491bf3 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 19 Apr 2015 22:13:41 -0400 Subject: [PATCH] CRM-16305 - Fix autofill of onBehalf profile fields --- CRM/Core/Page/AJAX/Location.php | 9 +++------ .../CRM/Contribute/Form/Contribution/OnBehalfOf.tpl | 13 +++---------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/CRM/Core/Page/AJAX/Location.php b/CRM/Core/Page/AJAX/Location.php index 0c567c9980..2943af6dfd 100644 --- a/CRM/Core/Page/AJAX/Location.php +++ b/CRM/Core/Page/AJAX/Location.php @@ -169,16 +169,13 @@ class CRM_Core_Page_AJAX_Location { $elements["onbehalf_{$key}"]['value'][$k] = $v; } } - elseif ($htmlType == 'Multi-Select') { - foreach ($defaults[$key] as $k => $v) { - $elements["onbehalf_{$key}"]['type'] = $htmlType; - $elements["onbehalf_{$key}"]['value'][$k] = $v; - } + elseif (strstr($htmlType, 'Multi-Select') && $htmlType != 'AdvMulti-Select') { + $elements["onbehalf_{$key}"]['type'] = 'Multi-Select'; + $elements["onbehalf_{$key}"]['value'] = array_values($defaults[$key]); } elseif ($htmlType == 'Autocomplete-Select') { $elements["onbehalf_{$key}"]['type'] = $htmlType; $elements["onbehalf_{$key}"]['value'] = $defaults[$key]; - $elements["onbehalf_{$key}"]['id'] = $defaults["{$key}_id"]; } elseif ($htmlType == 'Select Date') { $elements["onbehalf_{$key}"]['type'] = $htmlType; diff --git a/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl b/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl index e2600ee607..c94db9ab75 100644 --- a/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl +++ b/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl @@ -109,7 +109,6 @@ {$form.onbehalf.$fieldName.html} {if !empty($onBehalfOfFields.$fieldName.html_type) && $onBehalfOfFields.$fieldName.html_type eq 'Autocomplete-Select'} {assign var=elementName value=onbehalf[$fieldName]} - {include file="CRM/Custom/Form/AutoComplete.tpl" element_name=$elementName} {/if} {if $onBehalfOfFields.$fieldName.name|substr:0:5 eq 'phone'} {assign var="phone_ext_field" value=$onBehalfOfFields.$fieldName.name|replace:'phone':'phone_ext'} @@ -225,6 +224,9 @@ function setLocationDetails(contactID , reset) { cj(this).off('.autofill').val(cj(this).data('newVal')).change(); }); } + else if (cj('#' + ele).data('select2')) { + cj('#' + ele).select2('val', data[ele].value); + } if (data[ele].type == 'Radio') { if (data[ele].value) { var fldName = ele.replace('onbehalf_', ''); @@ -237,15 +239,6 @@ function setLocationDetails(contactID , reset) { cj("input[name='onbehalf["+ fldName+"]["+ selectedOption +"]']").prop('checked','checked'); } } - else if (data[ele].type == 'Multi-Select') { - for (var selectedOption in data[ele].value) { - cj('#' + ele + " option[value='" + selectedOption + "']").prop('selected', true); - } - } - else if (data[ele].type == 'Autocomplete-Select') { - cj('#' + ele ).val( data[ele].value ); - cj('#' + ele + '_id').val(data[ele].id); - } else if (data[ele].type == 'AdvMulti-Select') { var customFld = ele.replace('onbehalf_', ''); // remove empty value if any -- 2.25.1