Afform - Use list of allowed operators if set on the form, adjust width
authorcolemanw <coleman@civicrm.org>
Wed, 4 Oct 2023 12:32:03 +0000 (08:32 -0400)
committercolemanw <coleman@civicrm.org>
Tue, 2 Jan 2024 23:13:03 +0000 (18:13 -0500)
ext/afform/core/Civi/Afform/AfformMetadataInjector.php
ext/afform/core/ang/af/afFieldWithSearchOperator.html
ext/afform/core/ang/afCore.css

index e92c63800650d4a1cf1fe7dca0776288bcc1d446..99ccaf77e2736342083f568f7e62565078605a32 100644 (file)
@@ -126,8 +126,13 @@ class AfformMetadataInjector {
       // If 'operators' is present in the field definition, use it as a limiter
       // Afform expects 'operators' in the fieldDefn to be associative key/label, not just a flat array
       // like it is in the schema.
-      if (!empty($fieldInfo['operators'])) {
-        $operators = array_intersect_key($operators, array_flip($fieldInfo['operators']));
+      $allowedOperators = $fieldInfo['operators'] ?? NULL;
+      // Use list of allowed operators if set on the form (should be in js plain array format)
+      if (!empty($fieldDefn['operators'])) {
+        $allowedOperators = \CRM_Utils_JS::decode($fieldDefn['operators']);
+      }
+      if ($allowedOperators) {
+        $operators = array_intersect_key($operators, array_flip($allowedOperators));
       }
       $fieldDefn['operators'] = \CRM_Utils_JS::encode($operators);
     }
index 3260716756c92cf264c23d2f56671dd698ec0201..fbc037c3efac22b2b7801e97467a2cb372bca9b0 100644 (file)
@@ -1,4 +1,4 @@
-<select class="form-control" crm-ui-select ng-model="$ctrl.search_operator" ng-change="$ctrl.onChangeOperator()">
+<select class="form-control afform-search-operator" crm-ui-select ng-model="$ctrl.search_operator" ng-change="$ctrl.onChangeOperator()">
   <option ng-repeat="(name, label) in $ctrl.defn.operators" value="{{ name }}">{{ label }}</option>
 </select>
 <div class="crm-af-field" ng-include="'~/af/fields/' + $ctrl.defn.input_type + '.html'"></div>
index 86c4d09b6ce6c1935f63ef9e5bd088df1ba5b691..317cd1c473d764e182aed8e98e9d00f3c24dd397 100644 (file)
@@ -36,6 +36,10 @@ af-form {
   display: inline-block;
 }
 
+#bootstrap-theme .input-group .afform-search-operator {
+  width: 6rem;
+}
+
 [af-repeat-item] {
   position: relative;
 }