From 9b4979aa9f5b9377b52a1908d06dbe3cf153ccf0 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 10 Aug 2022 16:53:54 -0400 Subject: [PATCH] CrmUi - Fix crmSelect2 to work with ngOptions As part of https://github.com/civicrm/civicrm-core/pull/23749 select elements using ui-jq were switched to crm-ui-select, which should have been a drop-in replacement, but it turns out it broke for widgets using ngOptions. This fixes it. Fixes dev/core#3797 --- ang/crmUi.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ang/crmUi.js b/ang/crmUi.js index 1e59ef0dbd..cd59407bd2 100644 --- a/ang/crmUi.js +++ b/ang/crmUi.js @@ -600,7 +600,7 @@ // In cases where UI initiates update, there may be an extra // call to refreshUI, but it doesn't create a cycle. - if (ngModel) { + if (ngModel && !attrs.ngOptions) { ngModel.$render = function () { $timeout(function () { // ex: msg_template_id adds new item then selects it; use $timeout to ensure that @@ -631,9 +631,16 @@ } } - // If using ngOptions, wait for them to load + // If using ngOptions, the above methods do not work because option values get rewritten. + // Skip init and do something simpler. if (attrs.ngOptions) { - $timeout(init); + $timeout(function() { + element.crmSelect2(scope.crmUiSelect || {}); + // Ensure widget is updated when model changes + ngModel.$render = function () { + element.val(ngModel.$viewValue || '').change(); + }; + }); } else { init(); } -- 2.25.1