unset($apiRequest['params']['context'], $apiRequest['params']['field']);
$baoName = _civicrm_api3_get_BAO($apiRequest['entity']);
- $options = $baoName::buildOptions($fieldName, $context, $apiRequest['params']);
+ $options = $output = $baoName::buildOptions($fieldName, $context, $apiRequest['params']);
if ($options === FALSE) {
return civicrm_api3_create_error("The field '{$fieldName}' has no associated option list.");
}
- return civicrm_api3_create_success($options);
+ // Support 'sequential' output as a non-associative array
+ if (!empty($apiRequest['params']['sequential'])) {
+ $output = array();
+ foreach ($options as $key => $val) {
+ $output[] = array('key' => $key, 'value' => $val);
+ }
+ }
+ return civicrm_api3_create_success($output);
}
/**
*/
function fetchOptions(row, field) {
if (CRM.searchBuilder.fieldOptions[field] === 'yesno') {
- CRM.searchBuilder.fieldOptions[field] = {1: ts('Yes'), 0: ts('No')};
+ CRM.searchBuilder.fieldOptions[field] = [{key: 1, value: ts('Yes')}, {key: 0, value: ts('No')}];
}
if (typeof(CRM.searchBuilder.fieldOptions[field]) == 'string') {
- CRM.api(CRM.searchBuilder.fieldOptions[field], 'getoptions', {field: field}, {
+ CRM.api(CRM.searchBuilder.fieldOptions[field], 'getoptions', {field: field, sequential: 1}, {
success: function(result, settings) {
var field = settings.field;
if (result.count) {
options = [options[0]];
}
}
- $.each(CRM.searchBuilder.fieldOptions[field], function(value, label) {
- var selected = ($.inArray(value, options) > -1) ? 'selected="selected"' : '';
- select.append('<option value="' + value + '"' + selected + '>' + label + '</option>');
+ $.each(CRM.searchBuilder.fieldOptions[field], function(key, option) {
+ var selected = ($.inArray(option.key, options) > -1) ? 'selected="selected"' : '';
+ select.append('<option value="' + option.key + '"' + selected + '>' + option.value + '</option>');
});
select.change();
}