Fix onCrmUiSelect to use current scope and apply to the digest cycle
authorColeman Watts <coleman@civicrm.org>
Fri, 16 Jul 2021 19:11:36 +0000 (15:11 -0400)
committerColeman Watts <coleman@civicrm.org>
Fri, 16 Jul 2021 19:42:08 +0000 (15:42 -0400)
Evaluates expression in current scope rather than parent scope,
and uses $scope.$apply.

ang/crmUi.js

index 7daef656ccededda09ed128a954d697ef2360159..16ef03f0ba84fe85a478872a635b9d1e4b47efb6 100644 (file)
     // Use a select2 widget as a pick-list. Instead of updating ngModel, the select2 widget will fire an event.
     // This similar to ngModel+ngChange, except that value is never stored in a model. It is only fired in the event.
     // usage: <select crm-ui-select='{...}' on-crm-ui-select="alert("User picked this item: " + selection)"></select>
-    .directive('onCrmUiSelect', function ($parse) {
+    .directive('onCrmUiSelect', function () {
       return {
         priority: 10,
         link: function (scope, element, attrs) {
           element.on('select2-selecting', function(e) {
             e.preventDefault();
             element.select2('close').select2('val', '');
-            scope.$parent.$eval(attrs.onCrmUiSelect, {selection: e.val});
+            scope.$apply(function() {
+              scope.$eval(attrs.onCrmUiSelect, {selection: e.val});
+            });
           });
         }
       };