From 27bed3cb61befe4f768d86fafaae93e9fa419266 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 16 Jul 2020 14:18:48 -0400 Subject: [PATCH] Search Ext: fix loading options and parsing custom field names --- ext/search/ang/search.module.js | 16 ++++++++++++++-- ext/search/ang/search/crmSearch.component.js | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ext/search/ang/search.module.js b/ext/search/ang/search.module.js index 433383ed68..f80d290b98 100644 --- a/ext/search/ang/search.module.js +++ b/ext/search/ang/search.module.js @@ -39,6 +39,18 @@ joinEntity = dotSplit.length > 1 ? dotSplit[0] : null, fieldName = _.last(dotSplit).split(':')[0], entityName = searchEntity; + // Custom fields contain a dot in their fieldname + // If 3 segments, the first is the joinEntity and the last 2 are the custom field + if (dotSplit.length === 3) { + fieldName = dotSplit[1] + '.' + fieldName; + } + // If 2 segments, it's ambiguous whether this is a custom field or joined field. Search the main entity first. + if (dotSplit.length === 2) { + var field = _.find(getEntity(true).fields, {name: dotSplit[0] + '.' + fieldName}); + if (field) { + return field; + } + } if (joinEntity) { entityName = _.find(CRM.vars.search.links[entityName], {alias: joinEntity}).entity; } @@ -57,9 +69,9 @@ } result.field = getField(fieldName); var split = fieldName.split(':'), - dotPos = split[0].indexOf('.'); + prefixPos = split[0].indexOf(result.field.name); result.path = split[0]; - result.prefix = result.path.substring(0, dotPos + 1); + result.prefix = prefixPos > 0 ? result.path.substring(0, prefixPos) : ''; result.suffix = !split[1] ? '' : ':' + split[1]; return result; } diff --git a/ext/search/ang/search/crmSearch.component.js b/ext/search/ang/search/crmSearch.component.js index 300093736b..3ec65608b0 100644 --- a/ext/search/ang/search/crmSearch.component.js +++ b/ext/search/ang/search/crmSearch.component.js @@ -458,8 +458,6 @@ } this.$onInit = function() { - loadFieldOptions(); - $scope.$bindToRoute({ expr: '$ctrl.params.select', param: 'select', @@ -516,6 +514,8 @@ }); } $scope.$watch('$ctrl.params.having', onChangeFilters, true); + + loadFieldOptions(); }; $scope.saveGroup = function() { -- 2.25.1