};
};
- ctrl.getAutocompleteFieldName = function() {
- return ctrl.afFieldset.modelName + (ctrl.afJoin ? ('+' + ctrl.afJoin.entity) : '') + ':' + ctrl.fieldName;
+ ctrl.getAutocompleteParams = function() {
+ return {
+ formName: 'afform:' + ctrl.afFieldset.getFormName(),
+ fieldName: ctrl.afFieldset.getName() + ':' + ctrl.fieldName,
+ values: $scope.dataProvider.getFieldData()
+ };
};
$scope.getOptions = function () {
ng-model="getSetSelect"
ng-model-options="{getterSetter: true}"
crm-autocomplete="$ctrl.defn.fk_entity"
- crm-autocomplete-params="{formName: 'afform:' + $ctrl.afFieldset.getFormName(), fieldName: $ctrl.afFieldset.getName() + ':' + $ctrl.fieldName, values: dataProvider.getFieldData()}"
+ crm-autocomplete-params="$ctrl.getAutocompleteParams"
multi="$ctrl.defn.input_attrs.multiple"
auto-open="$ctrl.defn.input_attrs.autoOpen"
quick-add="$ctrl.defn.input_attrs.quickAdd"
// Autocomplete based on APIv4 and Select2.
$.fn.crmAutocomplete = function(entityName, apiParams, select2Options) {
+ function getApiParams() {
+ if (typeof apiParams === 'function') {
+ return apiParams();
+ }
+ return apiParams || {};
+ }
if (entityName === 'destroy') {
return $(this).off('.crmEntity').crmSelect2('destroy');
}
const $el = $(this).off('.crmEntity');
let staticItems = getStaticOptions(select2Options.static),
quickAddLinks = select2Options.quickAdd,
- multiple = !!select2Options.multiple,
- key = apiParams.key || 'id';
+ multiple = !!select2Options.multiple;
$el.crmSelect2(_.extend({
ajax: {
return {params: JSON.stringify(_.assign({
input: input,
page: pageNum || 1
- }, apiParams))};
+ }, getApiParams()))};
},
results: function(data) {
return {
if (!idsNeeded.length) {
callback(multiple ? existing : existing[0]);
} else {
- var params = $.extend({}, apiParams || {}, {ids: idsNeeded});
+ var params = $.extend({}, getApiParams(), {ids: idsNeeded});
CRM.api4(entityName, 'autocomplete', params).then(function (result) {
callback(multiple ? result.concat(existing) : result[0]);
});
const response = data.submissionResponse && data.submissionResponse[0];
let createdId;
if (typeof response === 'object') {
+ let key = getApiParams().key || 'id';
// Loop through entities created by the afform (there should be only one)
Object.keys(response).forEach((entity) => {
if (Array.isArray(response[entity]) && response[entity][0] && response[entity][0][key]) {