{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('<option value="">' + placeholder + '</option>');
+ 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('<option value="">' + placeholder + '</option>');
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 += '<option value="' + this.value + '">' + this.name + '</option>';
});
- 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}