From: kurund Date: Mon, 8 Sep 2014 18:38:50 +0000 (+0530) Subject: CRM-15181, setdefault fixes for state/country X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0f449ae69a1849c76c146cf0a6e9f2d4c0a058bf;p=civicrm-core.git CRM-15181, setdefault fixes for state/country ---------------------------------------- * CRM-15181: on behalf of profile: adv multi-select fails with preset options https://issues.civicrm.org/jira/browse/CRM-15181 --- diff --git a/CRM/Core/Page/AJAX/Location.php b/CRM/Core/Page/AJAX/Location.php index 90e553da63..3ffdf59cde 100644 --- a/CRM/Core/Page/AJAX/Location.php +++ b/CRM/Core/Page/AJAX/Location.php @@ -137,12 +137,16 @@ class CRM_Core_Page_AJAX_Location { foreach ($addressFields as $field) { if (array_key_exists($field, $addressSequence)) { $addField = $field; + $type = 'Text'; if (in_array($field, array( 'state_province', 'country'))) { $addField = "{$field}_id"; + $type = 'Select2'; } $elements["onbehalf_{$field}-{$locTypeId}"] = array( - 'type' => 'Text', + 'fld' => $field, + 'locTypeId' => $locTypeId, + 'type' => $type, 'value' => isset($location['address'][1]) ? $location['address'][1][$addField] : null, ); unset($profileFields["{$field}-{$locTypeId}"]); diff --git a/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl b/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl index 58e4ef82fc..d45327f365 100644 --- a/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl +++ b/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl @@ -203,12 +203,13 @@ function setLocationDetails(contactID , reset) { var submittedOnBehalfInfo = {/literal}'{$submittedOnBehalfInfo}'{literal}; if (submittedOnBehalfInfo) { submittedOnBehalfInfo = cj.parseJSON(submittedOnBehalfInfo); - } - if (submittedCID == contactID) { - cj.each(submittedOnBehalfInfo, function(key, value) { - cj('#onbehalf_' + key ).val(value); - }); - return; + + if (submittedCID == contactID) { + cj.each(submittedOnBehalfInfo, function(key, value) { + cj('#onbehalf_' + key ).val(value); + }); + return; + } } resetValues(); @@ -234,6 +235,16 @@ function setLocationDetails(contactID , reset) { cj('#' + ele + " option[value='" + selectedOption + "']").prop('selected', true); } } + else if (data[ele].type == 'Select2') { + if (data[ele].fld == 'country') { + cj('#' + ele ).select2('val', data[ele].value).change(function() { + var stateField = 'onbehalf_state_province-' + data[ele].locTypeId; + if (stateField.length > 0 ) { + cj('#' + stateField).select2('val', data[stateField].value); + } + }).change(); + } + } else if (data[ele].type == 'Autocomplete-Select') { cj('#' + ele ).val( data[ele].value ); cj('#' + ele + '_id').val(data[ele].id);