Allow crmUiSelect to function without an attached model
authorColeman Watts <coleman@civicrm.org>
Mon, 27 Apr 2015 17:23:14 +0000 (11:23 -0600)
committerColeman Watts <coleman@civicrm.org>
Mon, 27 Apr 2015 17:23:14 +0000 (11:23 -0600)
ang/crmUi.js

index de2e078246463eebb641ba66f27c32dbda3585d1..312e921cdd9ddd811762aa35ffd9cdc1dffa6b51 100644 (file)
           // In cases where UI initiates update, there may be an extra
           // call to refreshUI, but it doesn't create a cycle.
 
-          ngModel.$render = function () {
-            $timeout(function () {
-              // ex: msg_template_id adds new item then selects it; use $timeout to ensure that
-              // new item is added before selection is made
-              element.select2('val', ngModel.$viewValue);
-            });
-          };
+          if (ngModel) {
+            ngModel.$render = function () {
+              $timeout(function () {
+                // ex: msg_template_id adds new item then selects it; use $timeout to ensure that
+                // new item is added before selection is made
+                element.select2('val', ngModel.$viewValue);
+              });
+            };
+          }
           function refreshModel() {
             var oldValue = ngModel.$viewValue, newValue = element.select2('val');
             if (oldValue != newValue) {
           function init() {
             // TODO watch select2-options
             element.select2(scope.crmUiSelect || {});
-            element.on('change', refreshModel);
-            $timeout(ngModel.$render);
+            if (ngModel) {
+              element.on('change', refreshModel);
+              $timeout(ngModel.$render);
+            }
           }
 
           init();
           }
 
           function init() {
-            // TODO watch options
             // TODO can we infer "entity" from model?
             element.crmEntityRef(scope.crmEntityref || {});
             element.on('change', refreshModel);