From ecd9ce3ba23ad7a6fccf4f3b34bd91b90bc02141 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 21 Jun 2021 19:53:34 -0700 Subject: [PATCH] crmUi - Add onCrmUiSelect for using select2 as a picklist --- ang/crmUi.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ang/crmUi.js b/ang/crmUi.js index 20ee8b1a8f10..7daef656cced 100644 --- a/ang/crmUi.js +++ b/ang/crmUi.js @@ -633,6 +633,22 @@ }; }) + // Use a select2 widget as a pick-list. Instead of updating ngModel, the select2 widget will fire an event. + // This similar to ngModel+ngChange, except that value is never stored in a model. It is only fired in the event. + // usage: + .directive('onCrmUiSelect', function ($parse) { + return { + priority: 10, + link: function (scope, element, attrs) { + element.on('select2-selecting', function(e) { + e.preventDefault(); + element.select2('close').select2('val', ''); + scope.$parent.$eval(attrs.onCrmUiSelect, {selection: e.val}); + }); + } + }; + }) + // Render a crmEntityRef widget // usage: .directive('crmEntityref', function ($parse, $timeout) {