diff --git a/ang/crmUi.js b/ang/crmUi.js index d06de24e8a6d..92852bd8d98e 100644 --- a/ang/crmUi.js +++ b/ang/crmUi.js @@ -777,7 +777,7 @@ $timeout(function() { $element.crmAutocomplete(ctrl.entity, ctrl.crmAutocompleteParams, { multiple: ctrl.multi, - minimumInputLength: ctrl.autoOpen && !ctrl.staticOptions ? 0 : 1, + minimumInputLength: ctrl.autoOpen && _.isEmpty(ctrl.staticOptions) ? 0 : 1, static: ctrl.staticOptions || [], }); }); diff --git a/ext/search_kit/ang/crmSearchAdmin.module.js b/ext/search_kit/ang/crmSearchAdmin.module.js index 1669081dcbd7..f4fffa91f055 100644 --- a/ext/search_kit/ang/crmSearchAdmin.module.js +++ b/ext/search_kit/ang/crmSearchAdmin.module.js @@ -398,7 +398,10 @@ entity.optionsLoaded = false; entitiesToLoad[entityName] = [entityName, 'getFields', { loadOptions: ['id', 'name', 'label', 'description', 'color', 'icon'], - where: [['options', '!=', false]], + // For fields with both an FK and an option list, prefer the FK + // because it's more efficient to render an autocomplete than to + // pre-load potentially thousands of options into a select dropdown. + where: [['options', '!=', false], ['fk_entity', 'IS NULL']], select: ['options'] }, {name: 'options'}]; } diff --git a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js index 15bebbe47724..a8e0893b9862 100644 --- a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js @@ -532,7 +532,8 @@ prefix = typeof prefix === 'undefined' ? '' : prefix; _.each(fields, function(field) { var item = { - id: prefix + field.name + (field.suffixes && _.includes(field.suffixes, suffix.replace(':', '')) ? suffix : ''), + // Use suffix only if the field is not an FK. EntityRef fields look-up by id. + id: prefix + field.name + (!field.fk_entity && _.includes(field.suffixes || [], suffix.replace(':', '')) ? suffix : ''), text: field.label, description: field.description }; diff --git a/ext/search_kit/ang/crmSearchTasks/crmSearchInput/crmSearchInputVal.component.js b/ext/search_kit/ang/crmSearchTasks/crmSearchInput/crmSearchInputVal.component.js index 9419d338d3d3..b48165a03045 100644 --- a/ext/search_kit/ang/crmSearchTasks/crmSearchInput/crmSearchInputVal.component.js +++ b/ext/search_kit/ang/crmSearchTasks/crmSearchInput/crmSearchInputVal.component.js @@ -142,12 +142,16 @@ return '~/crmSearchTasks/crmSearchInput/boolean.html'; } - if (field.options) { - return '~/crmSearchTasks/crmSearchInput/select.html'; - } - - if ((field.fk_entity || field.name === 'id') && !_.includes(['>', '<', '>=', '<='], ctrl.op)) { - return '~/crmSearchTasks/crmSearchInput/entityRef.html'; + if (!_.includes(['>', '<', '>=', '<='], ctrl.op)) { + // For fields with both an FK and an option list, prefer the FK + // because it's more efficient to render an autocomplete than to + // pre-load potentially thousands of options into a select dropdown. + if ((field.fk_entity || field.name === 'id')) { + return '~/crmSearchTasks/crmSearchInput/entityRef.html'; + } + if (field.options) { + return '~/crmSearchTasks/crmSearchInput/select.html'; + } } if (field.data_type === 'Integer') {