Skip to content

Commit

Permalink
Merge pull request #506 from jitendrapurohit/CRM-20734
Browse files Browse the repository at this point in the history
CRM-20734: Populate state if country is selected by default on page load
  • Loading branch information
colemanw authored Nov 21, 2017
2 parents 57f48ce + 57a37e4 commit 8f56584
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions modules/views/civicrm/civicrm_handler_filter_state_multi.inc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class civicrm_handler_filter_state_multi extends views_handler_filter_in_operato

// get the country filter
$filters = is_array($this->view->filter) ? $this->view->filter : array();
$state = '';
foreach ($filters as $name => $handler) {
if ($handler->definition['handler'] == 'civicrm_handler_filter_country_multi') {
$country_field = $handler->field;
Expand Down Expand Up @@ -82,6 +83,9 @@ class civicrm_handler_filter_state_multi extends views_handler_filter_in_operato
drupal_add_js(array('civicrm_views' => array('states' => $state_html)), 'setting');
$c_object = json_encode($state_html);
}
if ($handler->definition['handler'] == 'civicrm_handler_filter_state_multi') {
$state = CRM_Utils_Array::value($handler->field, $_GET);
}
}

// country filter exists, remove options, add js
Expand All @@ -92,9 +96,13 @@ class civicrm_handler_filter_state_multi extends views_handler_filter_in_operato
$js = "(function ($) {
Drupal.behaviors.civicrm_views_{$fid} = {
attach: function (context, settings) {
$('#edit-{$country_field}').change(function() {
if ($('#edit-{$country_field}').val() && !settings.state) {
load_state();
}
function load_state() {
var country = $('#edit-{$country_field}');
var stateList = '<option value=\"All\">&lt;Any&gt;</option>';
var selectedCountries = $(this).val();
var selectedCountries = country.val();
// ensure selectedCountries is an array
if ($.type(selectedCountries) === 'string') {
selectedCountries = [selectedCountries];
Expand All @@ -103,11 +111,13 @@ class civicrm_handler_filter_state_multi extends views_handler_filter_in_operato
stateList = stateList + (Drupal.settings.civicrm_views.states[selectedCountry] || '');
});
$('select[name={$this->field}]').empty().html(stateList);
});
}
$('#edit-{$country_field}').change(load_state);
}
}
})(jQuery);";
drupal_add_js($js, 'inline', 'footer');
drupal_add_js(array('state' => $state), 'setting');
}
}

Expand Down

0 comments on commit 8f56584

Please sign in to comment.