CRM-15327 - Fix autofill of chain-select
authorColeman Watts <coleman@civicrm.org>
Tue, 30 Sep 2014 20:08:58 +0000 (16:08 -0400)
committerColeman Watts <coleman@civicrm.org>
Mon, 6 Oct 2014 17:40:18 +0000 (13:40 -0400)
CRM/Core/Page/AJAX/Location.php
templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl

index 831b590d2eaed4690662ac5f5aa820740a4dd68f..a5b4002caf81bbc5779f314bd45a8a51c1917cb1 100644 (file)
@@ -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,
           );
index a63e56742d093f0b8a64e9b754769296c97da984..b28925e8e7539728fdef674498db25c0197e85c0 100644 (file)
@@ -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();
         }
       }
     },