From: Coleman Watts Date: Mon, 27 Apr 2015 17:23:14 +0000 (-0600) Subject: Allow crmUiSelect to function without an attached model X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c81696a601756918968676d6cd16097353e6c35f;p=civicrm-core.git Allow crmUiSelect to function without an attached model --- 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);