SearchKit - Set better default when selecting math function
authorColeman Watts <coleman@civicrm.org>
Thu, 27 Oct 2022 03:17:21 +0000 (23:17 -0400)
committerColeman Watts <coleman@civicrm.org>
Mon, 31 Oct 2022 14:38:32 +0000 (10:38 -0400)
Instead of a blank field selector with no way to clear it,
it now picks the first available field for you so it's easier to clear
and replace with a number if you so choose.

ext/search_kit/ang/crmSearchAdmin/crmSearchFunction.component.js

index 86e063834f953d4d48aee3553826ddbcb874901b..a9c7496cdd5e85e3213d4f08e4563d1f2e83e61b 100644 (file)
       });
 
       this.addArg = function(exprType) {
-        var param = ctrl.getParam(ctrl.args.length);
+        var param = ctrl.getParam(ctrl.args.length),
+          val = '';
+        if (exprType === 'SqlNumber') {
+          // Number: default to 0
+          val = 0;
+        } else if (exprType === 'SqlField') {
+          // Field: Default to first available field, making it easier to delete the value
+          val = ctrl.getFields().results[0].children[0].id;
+        }
         ctrl.args.push({
           type: ctrl.exprTypes[exprType].type,
           flag_before: _.filter(_.keys(param.flag_before))[0],
           name: param.name,
-          value: exprType === 'SqlNumber' ? 0 : ''
+          value: val
         });
       };