From 2f50fc9253aebdbd5a9e2c502b2b8fa5f6e16b75 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 9 Dec 2013 20:43:59 -0800 Subject: [PATCH] CRM-13933 - Fix chainSelect to work in other contexts --- templates/CRM/common/stateCountry.tpl | 29 ++++++++++++++------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/templates/CRM/common/stateCountry.tpl b/templates/CRM/common/stateCountry.tpl index adf578eebc..7bf621203a 100644 --- a/templates/CRM/common/stateCountry.tpl +++ b/templates/CRM/common/stateCountry.tpl @@ -28,36 +28,37 @@ {literal} cj(function($) { function chainSelect(e) { - var val = e.data.target.val(); - var placeholder = $(this).val() ? "{/literal}{ts escape='js'}Loading{/ts}{literal}..." : e.data.placeholder; - e.data.target.html(''); + var info = $(this).data('chainSelect'); + var val = info.target.val(); + var placeholder = $(this).val() ? "{/literal}{ts escape='js'}Loading{/ts}{literal}..." : info.placeholder; + info.target.html(''); if ($(this).val()) { - $.getJSON(e.data.callback, {_value: $(this).val()}, function(data) { + $.getJSON(info.callback, {_value: $(this).val()}, function(data) { var options = ''; $.each(data, function() { options += ''; }); - e.data.target.html(options).val(val).trigger('change'); + info.target.html(options).val(val).trigger('change'); }); } else { - e.data.target.trigger('change'); + info.target.trigger('change'); } } {/literal} {foreach from=$config->stateCountryMap item=stateCountryMap} {if $stateCountryMap.country && $stateCountryMap.state_province} - $('select[name="{$stateCountryMap.country}"]').on('change', {literal}{ + $('select[name="{$stateCountryMap.country}"], #{$stateCountryMap.country}').data('chainSelect', {ldelim} callback: CRM.url('civicrm/ajax/jqState'), - target: $('select[name="{/literal}{$stateCountryMap.state_province}{literal}"]'), - placeholder: "{/literal}{ts escape='js'}(choose country first){/ts}{literal}" - }{/literal}, chainSelect); + target: $('select[name="{$stateCountryMap.state_province}"], #{$stateCountryMap.state_province}'), + placeholder: "{ts escape='js'}(choose country first){/ts}" + {rdelim}).on('change', chainSelect); {/if} {if $stateCountryMap.state_province && $stateCountryMap.county} - $('select[name="{$stateCountryMap.state_province}"]').on('change', {literal}{ + $('select[name="{$stateCountryMap.state_province}"], #{$stateCountryMap.state_province}').data('chainSelect', {ldelim} callback: CRM.url('civicrm/ajax/jqCounty'), - target: $('select[name="{/literal}{$stateCountryMap.county}{literal}"]'), - placeholder: "{/literal}{ts escape='js'}(choose state first){/ts}{literal}" - }{/literal}, chainSelect); + target: $('select[name="{$stateCountryMap.county}"], #{$stateCountryMap.county}'), + placeholder: "{ts escape='js'}(choose state first){/ts}" + {rdelim}).on('change', chainSelect); {/if} {/foreach} {literal} -- 2.25.1