CRM-13933 - Fix chainSelect to work in other contexts
authorColeman Watts <coleman@civicrm.org>
Tue, 10 Dec 2013 04:43:59 +0000 (20:43 -0800)
committerColeman Watts <coleman@civicrm.org>
Tue, 10 Dec 2013 04:43:59 +0000 (20:43 -0800)
templates/CRM/common/stateCountry.tpl

index adf578eebc422662fc32deb63db909f806e9f5bd..7bf621203af622659b40c8563f0e037368a064c3 100644 (file)
   {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}