Skip to content

Commit

Permalink
Merge pull request #24224 from colemanw/fixSelect2AndNgOptions
Browse files Browse the repository at this point in the history
CrmUi - Fix crmSelect2 to work with ngOptions
  • Loading branch information
seamuslee001 authored Aug 11, 2022
2 parents d8a0db1 + 9b4979a commit f82fa0e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ang/crmUi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit f82fa0e

Please sign in to comment.