From: Coleman Watts Date: Sat, 22 Feb 2014 15:54:44 +0000 (-0500) Subject: CRM-13966 - Fix entityRef/getlist to work with non-id keys X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0724132dab543bba2fb179a4843182277ee78f12;p=civicrm-core.git CRM-13966 - Fix entityRef/getlist to work with non-id keys --- diff --git a/CRM/Core/Form/Renderer.php b/CRM/Core/Form/Renderer.php index dadd82e2e5..0c3c4dbef1 100644 --- a/CRM/Core/Form/Renderer.php +++ b/CRM/Core/Form/Renderer.php @@ -212,12 +212,14 @@ class CRM_Core_Form_Renderer extends HTML_QuickForm_Renderer_ArraySmarty { if ($val) { $entity = $field->getAttribute('data-api-entity'); $select = json_decode($field->getAttribute('data-select-params'), TRUE); + $api = json_decode($field->getAttribute('data-api-params'), TRUE); + $params = CRM_Utils_Array::value('params', $api, array()); // Support serialized values if (strpos($val, CRM_Core_DAO::VALUE_SEPARATOR) !== FALSE) { $val = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($val, CRM_Core_DAO::VALUE_SEPARATOR)); $field->setValue($val); } - $result = civicrm_api3($entity, 'getlist', array('params' => array('id' => $val))); + $result = civicrm_api3($entity, 'getlist', array('id' => $val, 'params' => $params)); if ($field->isFrozen()) { $field->removeAttribute('class'); } diff --git a/api/v3/Generic/Getlist.php b/api/v3/Generic/Getlist.php index 12bad54b9f..4ab281940f 100644 --- a/api/v3/Generic/Getlist.php +++ b/api/v3/Generic/Getlist.php @@ -73,7 +73,7 @@ function _civicrm_api3_generic_getList_defaults($entity, &$request) { 'page_num' => 1, 'input' => '', 'image_field' => NULL, - 'id_field' => 'id', + 'id_field' => $entity == 'option_value' ? 'value' : 'id', 'params' => array(), ); // Find main field from meta diff --git a/js/Common.js b/js/Common.js index 29198a3985..37577b1bcd 100644 --- a/js/Common.js +++ b/js/Common.js @@ -241,8 +241,6 @@ CRM.validate = CRM.validate || { (function ($, undefined) { "use strict"; - // Set select2 defaults - $.fn.select2.defaults.minimumResultsForSearch = 10; // https://github.com/ivaynberg/select2/pull/2090 $.fn.select2.defaults.width = 'resolve'; @@ -317,21 +315,21 @@ CRM.validate = CRM.validate || { }) .find('input.select-row:checked').parents('tr').addClass('crm-row-selected'); $('.crm-select2', e.target).each(function() { - var $el = $(this); + var $el = $(this), options = {}; // quickform doesn't support optgroups so here's a hack :( $('option[value^=crm_optgroup]', this).each(function() { $(this).nextUntil('option[value^=crm_optgroup]').wrapAll(''); $(this).remove(); }); - // Get a copy of the data rather than a reference - var options = $.extend({}, $el.data('select-params') || {}); - // Set placeholder from markup if not specified + // Defaults for single-selects if ($el.is('select:not([multiple])')) { - options.allowClear = options.allowClear !== undefined ? options.allowClear : !($el.hasClass('required')); - if (options.placeHolder === undefined && $('option:first', this).val() === '') { + options.minimumResultsForSearch = 10; + options.allowClear = !($el.hasClass('required')); + if ($('option:first', this).val() === '') { options.placeholderOption = 'first'; } } + $.extend(options, $el.data('select-params') || {}); // Autocomplete using the getlist api if ($el.data('api-entity') && $el.hasClass('crm-form-entityref')) { $el.addClass('crm-ajax-select');