Skip to content

Commit

Permalink
add support for counties.
Browse files Browse the repository at this point in the history
Note: this depends on this change to core being merged:

civicrm/civicrm-core#20309
  • Loading branch information
jmcclelland committed May 14, 2021
1 parent ee78a6d commit eec4710
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CRM/Remoteform/Page/RemoteForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ function sanitizeInput($input) {
'params' => $params,
);
}
if ($action == 'Countiesforstateprovince') {
$params['state_province_id'] = isset($input_params['state_province_id']) ? intval($input_params['state_province_id']) : NULL;
return array(
'entity' => 'RemoteForm',
'action' => 'Countiesforstateprovince',
'params' => $params,
);
}
if ($action == 'Countries') {
return array(
'entity' => 'RemoteForm',
Expand Down
8 changes: 0 additions & 8 deletions api/v3/RemoteForm/Counties.php

This file was deleted.

32 changes: 32 additions & 0 deletions api/v3/RemoteForm/Countiesforstateprovince.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
use CRM_Remoteform_ExtensionUtil as E;

/**
* RemoteForm.Countyforstateprovince API specification (optional)
* This is used for documentation and validation.
*
* @param array $spec description of fields supported by this API call
* @return void
* @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
*/
function _civicrm_api3_remote_form_Countiesforstateprovince_spec(&$params) {
$params['county_id']['title'] = 'State Province ID';
}

function civicrm_api3_remote_form_Countiesforstateprovince(&$params) {
$state_province_id = NULL;
$values = array();
if (array_key_exists('state_province_id', $params)) {
$state_province_id = $params['state_province_id'];
}
if (empty($state_province_id)) {
$state_province_id = Civi::settings()->get('defaultContactStateProvince');
if (empty($state_province_id)) {
// Rather then return all counties in the world, return nothing if no defaults.
return civicrm_api3_create_success([]);
}
}
$values = CRM_Core_PseudoConstant::countyForState($state_province_id);
return civicrm_api3_create_success($values);
}

11 changes: 11 additions & 0 deletions remoteform.js
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,12 @@ function remoteForm(config) {
args['params']['country_id'] = chosen;
label = 'State';
}
if (loc == 'county') {
action = 'Countiesforstateprovince';
key_field = 'county_id';
args['params']['state_province_id'] = chosen;
label = 'County';
}
else if (loc == 'country') {
action = 'Countries';
label = 'Country';
Expand Down Expand Up @@ -1264,8 +1270,13 @@ function remoteForm(config) {
}
else if (def.name == 'county_id') {
selectInput.className += ' remoteform-county';
loc = 'county';
}
else if (def.name == 'state_province_id') {
// We need to add a callback.
selectInput.addEventListener('change', function() {
populateLocationOptions('county', this.value);
});
selectInput.className += ' remoteform-state-province';
loc = 'state-province';
}
Expand Down

0 comments on commit eec4710

Please sign in to comment.