SearchKit - Fix selection of fields when creating a Data Segment
authorColeman Watts <coleman@civicrm.org>
Wed, 20 Apr 2022 22:41:00 +0000 (18:41 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 20 Apr 2022 22:41:00 +0000 (18:41 -0400)
ext/search_kit/ang/crmSearchAdmin/searchSegment/crmSearchAdminSegment.component.js

index 18c63adbca60897278b98b5be1cdfc9d92984d4b..e059acddd883254063a3dc349df247c38564c997 100644 (file)
@@ -6,7 +6,7 @@
       segmentId: '<',
     },
     templateUrl: '~/crmSearchAdmin/searchSegment/crmSearchAdminSegment.html',
-    controller: function ($scope, searchMeta, dialogService, crmApi4, crmStatus, formatForSelect2) {
+    controller: function ($scope, searchMeta, dialogService, crmApi4, crmStatus) {
       var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'),
         ctrl = this,
         originalEntity,
         return searchMeta.getField(fieldName, ctrl.segment.entity_name);
       };
 
+      // Select2-formatted fields that can be used in "when" clause, including :name suffix if applicable
       this.selectFields = function() {
-        return {results: formatForSelect2(searchMeta.getEntity(ctrl.segment.entity_name).fields, 'name', 'label', ['description'])};
+        var fields = {results: []};
+        _.each(searchMeta.getEntity(ctrl.segment.entity_name).fields, function(field) {
+          var item = {
+            id: field.name + (field.suffixes && _.includes(field.suffixes, 'name') ? ':name' : ''),
+            text: field.label,
+            description: field.description
+          };
+          fields.results.push(item);
+        });
+        return fields;
       };
 
       this.save = function() {