From a5ca92d313f611fe76bf0aa1154176838912d5ef Mon Sep 17 00:00:00 2001 From: Ankur Agarwal Date: Tue, 17 Jun 2014 22:58:41 +0530 Subject: [PATCH] custom function for model2Select & select2Model model2Select: function(model) { return model.name; }, select2Model: function(value) { return {'id': value, 'name': value}; }, --- src/select2.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/select2.js b/src/select2.js index 828032d..0677a80 100644 --- a/src/select2.js +++ b/src/select2.js @@ -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; @@ -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; } @@ -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; }