Merge pull request #19174 from eileenmcnaughton/conttype
[civicrm-core.git] / ext / search / ang / crmSearchAdmin / crmSearchClause.component.js
index 3c196a440b10307565874a4d2bf0cb01a1027ca7..de5ce60e43d8c1b0e222941f0d179fa76c9063f2 100644 (file)
         }
       };
 
-      // Add/remove value if operator allows for one
       this.changeClauseOperator = function(clause) {
+        // Add/remove value if operator allows for one
         if (_.contains(clause[1], 'NULL')) {
           clause.length = 2;
-        } else if (clause.length === 2) {
-          clause.push('');
+        } else {
+          if (clause.length === 2) {
+            clause.push('');
+          }
+          // Change multi/single value to/from an array
+          var shouldBeArray = (clause[1] === 'IN' || clause[1] === 'NOT IN' || clause[1] === 'BETWEEN' || clause[1] === 'NOT BETWEEN');
+          if (!_.isArray(clause[2]) && shouldBeArray) {
+            clause[2] = [];
+          } else if (_.isArray(clause[2]) && !shouldBeArray) {
+            clause[2] = '';
+          }
+          if (clause[1] === 'BETWEEN' || clause[1] === 'NOT BETWEEN') {
+            clause[2].length = 2;
+          }
         }
       };