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');
}
(function ($, undefined) {
"use strict";
- // Set select2 defaults
- $.fn.select2.defaults.minimumResultsForSearch = 10;
// https://github.com/ivaynberg/select2/pull/2090
$.fn.select2.defaults.width = 'resolve';
})
.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('<optgroup label="' + $(this).text() + '" />');
$(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');