From 2fd2fc793010519cb50457916a81d5624f3cc712 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 30 Sep 2014 16:08:58 -0400 Subject: [PATCH] CRM-15327 - Fix autofill of chain-select --- CRM/Core/Page/AJAX/Location.php | 10 ++++---- .../Form/Contribution/OnBehalfOf.tpl | 24 ++++++++----------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/CRM/Core/Page/AJAX/Location.php b/CRM/Core/Page/AJAX/Location.php index 831b590d2e..a5b4002caf 100644 --- a/CRM/Core/Page/AJAX/Location.php +++ b/CRM/Core/Page/AJAX/Location.php @@ -130,22 +130,20 @@ class CRM_Core_Page_AJAX_Location { 'supplemental_address_2', 'city', 'postal_code', - 'country', + 'county', 'state_province', + 'country', ); foreach ($addressFields as $field) { if (array_key_exists($field, $addressSequence)) { $addField = $field; $type = 'Text'; - if (in_array($field, array( - 'state_province', 'country'))) { + if (in_array($field, array('state_province', 'country', 'county'))) { $addField = "{$field}_id"; - $type = 'Select2'; + $type = 'Select'; } $elements["onbehalf_{$field}-{$locTypeId}"] = array( - 'fld' => $field, - 'locTypeId' => $locTypeId, 'type' => $type, 'value' => isset($location['address'][1]) ? $location['address'][1][$addField] : null, ); diff --git a/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl b/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl index a63e56742d..b28925e8e7 100644 --- a/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl +++ b/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl @@ -27,7 +27,6 @@ * This file provides the HTML for the on-behalf-of form. * Also used for related contact edit form. * FIXME: This is way more complex than it needs to be - * FIXME: About 1% of this javascript is needed for contribution forms * FIXME: Why are we not just using the dynamic form tpl to display this profile? *} @@ -169,8 +168,10 @@ function showOnBehalf(onBehalfRequired) { } function resetValues() { - cj('input[type=text], select, textarea', "#select_org div").not('#onbehalfof_id').val('').change(); - cj('input[type=radio], input[type=checkbox]', "#select_org tr td").prop('checked', false).change(); + // Don't trip chain-select when clearing values + cj('.crm-chain-select-control', "#select_org div").select2('val', ''); + cj('input[type=text], select, textarea', "#select_org div").not('.crm-chain-select-control, #onbehalfof_id').val('').change(); + cj('input[type=radio], input[type=checkbox]', "#select_org div").prop('checked', false).change(); } function createNew( ) { @@ -219,6 +220,11 @@ function setLocationDetails(contactID , reset) { timeout : 5000, //Time in milliseconds success : function(data, status) { for (var ele in data) { + if (cj("#"+ ele).hasClass('crm-chain-select-target')) { + cj("#"+ ele).data('newVal', data[ele].value).off('.autofill').on('crmOptionsUpdated.autofill', function() {console.log(this.id, cj(this).data('newVal')); + cj(this).off('.autofill').val(cj(this).data('newVal')).change(); + }); + } if (data[ele].type == 'Radio') { if (data[ele].value) { cj("input[name='"+ ele +"']").filter("[value=" + data[ele].value + "]").prop('checked', true); @@ -234,16 +240,6 @@ 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); @@ -262,7 +258,7 @@ function setLocationDetails(contactID , reset) { } } else { - cj('#' + ele ).val(data[ele].value); + cj('#' + ele ).val(data[ele].value).change(); } } }, -- 2.25.1