SearchKit - Fix field transformation UI to handle number 0
authorcolemanw <coleman@civicrm.org>
Sat, 4 Nov 2023 02:29:15 +0000 (22:29 -0400)
committercolemanw <coleman@civicrm.org>
Sat, 4 Nov 2023 02:31:22 +0000 (22:31 -0400)
This is the old number 0 is falsey bug.
To reproduce, add a field transformation such as if/else,
clear the field values and select numbers.
The number zero will be treated as empty and not work.

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

index bf4e16ab77e5c882635b35f2b9218141b75865c9..366bb69105649a50b477cefd356d910946403cf1 100644 (file)
       this.changeArg = function(index) {
         var val = ctrl.args[index].value;
         // Delete empty value
-        if (index && !val && ctrl.args.length > ctrl.fn.params[0].min_expr) {
+        if (index && !val && val !== 0 && ctrl.args.length > ctrl.fn.params[0].min_expr) {
           ctrl.args.splice(index, 1);
         }
         ctrl.writeExpr();
       this.writeExpr = function() {
         if (ctrl.fnName) {
           var args = _.transform(ctrl.args, function(args, arg, index) {
-            if (arg.value || arg.flag_before) {
+            if (arg.value || arg.value === 0 || arg.flag_before) {
               var prefix = arg.flag_before || arg.name ? (index ? ' ' : '') + (arg.flag_before || arg.name) + (arg.value ? ' ' : '') : (index ? ', ' : '');
               args.push(prefix + (arg.type === 'string' ? JSON.stringify(arg.value) : arg.value));
             }