Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

custom function for model2Select & select2Model #229

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec
var model;
if (opts.simple_tags) {
model = [];
angular.forEach(select2_data, function(value, index) {
model.push(value.id);
var model2Select = opts.model2Select || function(value, index) {
return value.id
}
angular.forEach(select2_data, function(value, index){
model.push(model2Select(value));
});
} else {
model = select2_data;
Expand All @@ -59,13 +62,15 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec
return model;
}

var select2Model = opts.select2Model || function(value) {
return {'id': value, 'text': value}
}

if (opts.simple_tags) {
model = [];
angular.forEach(
angular_data,
function(value, index) {
model.push({'id': value, 'text': value});
});
angular.forEach(angular_data, function(value, index){
model.push(select2Model(value));
});
} else {
model = angular_data;
}
Expand Down Expand Up @@ -149,7 +154,7 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec
// Set the view and model value and update the angular template manually for the ajax/multiple select2.
elm.bind("change", function (e) {
e.stopImmediatePropagation();

if (scope.$$phase || scope.$root.$$phase) {
return;
}
Expand Down