From c81696a601756918968676d6cd16097353e6c35f Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 27 Apr 2015 11:23:14 -0600 Subject: [PATCH] Allow crmUiSelect to function without an attached model --- ang/crmUi.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/ang/crmUi.js b/ang/crmUi.js index de2e078246..312e921cdd 100644 --- a/ang/crmUi.js +++ b/ang/crmUi.js @@ -616,13 +616,15 @@ // 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) { @@ -635,8 +637,10 @@ 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(); @@ -673,7 +677,6 @@ } function init() { - // TODO watch options // TODO can we infer "entity" from model? element.crmEntityRef(scope.crmEntityref || {}); element.on('change', refreshModel); -- 2.25.1