Skip to content

Commit

Permalink
crmUi - Add onCrmUiSelect for using select2 as a picklist
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Jul 7, 2021
1 parent 9718821 commit ecd9ce3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ang/crmUi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: <select crm-ui-select='{...}' on-crm-ui-select="alert("User picked this item: " + selection)"></select>
.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: <input crm-entityref="{entity: 'Contact', select: {allowClear:true}}" ng-model="myobj.field" />
.directive('crmEntityref', function ($parse, $timeout) {
Expand Down

0 comments on commit ecd9ce3

Please sign in to comment.