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

Support options.separator and external jQuery #213

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
12 changes: 10 additions & 2 deletions src/select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec
require: 'ngModel',
priority: 1,
compile: function (tElm, tAttrs) {
// Do this to use the external jQuery instead of angular.element
// if angular is loaded with jQlite and not jQuery
tElm = $(tElm[0]);

var watch,
repeatOption,
repeatAttr,
Expand All @@ -22,7 +26,7 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec

// Enable watching of the options dataset if in use
if (tElm.is('select')) {
repeatOption = tElm.find( 'optgroup[ng-repeat], optgroup[data-ng-repeat], option[ng-repeat], option[data-ng-repeat]');
repeatOption = tElm.find('optgroup[ng-repeat], optgroup[data-ng-repeat], option[ng-repeat], option[data-ng-repeat]');

if (repeatOption.length) {
repeatAttr = repeatOption.attr('ng-repeat') || repeatOption.attr('data-ng-repeat');
Expand All @@ -31,6 +35,10 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec
}

return function (scope, elm, attrs, controller) {
// Do this to use the external jQuery instead of angular.element
// if angular is loaded with jQlite and not jQuery
elm = $(elm[0]);

// instance-specific options
var opts = angular.extend({}, options, scope.$eval(attrs.uiSelect2));

Expand Down Expand Up @@ -98,7 +106,7 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec
if (opts.multiple) {
var viewValue = controller.$viewValue;
if (angular.isString(viewValue)) {
viewValue = viewValue.split(',');
viewValue = viewValue.split(opts.separator || ',');
}
elm.select2(
'data', convertToSelect2Model(viewValue));
Expand Down