Afform - refactor add value to use new onCrmUiSelect directive
authorColeman Watts <coleman@civicrm.org>
Thu, 23 Dec 2021 15:07:26 +0000 (10:07 -0500)
committerColeman Watts <coleman@civicrm.org>
Sun, 26 Dec 2021 19:05:41 +0000 (14:05 -0500)
ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js
ext/afform/admin/ang/afGuiEditor/afGuiEntity.html

index de487e19a7e1f588681dec0fdf02d4398f5feb7c..001a580b46ada8f173c476210856fee1569b4399 100644 (file)
         return found.match;
       }
 
+      this.addValue = function(fieldName) {
+        if (fieldName) {
+          if (!ctrl.entity.data) {
+            ctrl.entity.data = {};
+          }
+          ctrl.entity.data[fieldName] = '';
+        }
+      };
+
       this.$onInit = function() {
         // When a new block is saved, update the list
         this.meta = afGui.meta;
           $scope.controls.fieldSearch = '';
           ctrl.buildPaletteLists();
         });
-
-        $scope.$watch('controls.addValue', function(fieldName) {
-          if (fieldName) {
-            if (!ctrl.entity.data) {
-              ctrl.entity.data = {};
-            }
-            ctrl.entity.data[fieldName] = '';
-            $scope.controls.addValue = '';
-          }
-        });
       };
     }
   });
index a92c376322a7bb5f163b454530ae23fea291853a..712e648dfbad3fcac673a289e40cdeca26404092 100644 (file)
@@ -10,7 +10,7 @@
     </div>
     <hr />
     <div class="form-inline">
-      <input class="form-control" ng-model="controls.addValue" crm-ui-select="{data: valuesFields}" placeholder="Add value" />
+      <input class="form-control" on-crm-ui-select="$ctrl.addValue(selection)" crm-ui-select="{data: valuesFields, placeholder: ts('Add value')}" />
     </div>
   </fieldset>