Skip to content
This repository was archived by the owner on Jan 27, 2018. It is now read-only.

Commit 15f6057

Browse files
author
Evan Oxfeld
committed
Mulitselect: Push only new items to options on scope
Fixes EvanOxfeld#4.
1 parent 6b75845 commit 15f6057

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

angular-selectize.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@
103103

104104
if (model.indexOf(value) === -1) {
105105
model.push(value);
106-
scope.$parent[optionsProperty].push(value);
106+
if (!option) {
107+
scope.$parent[optionsProperty].push(value);
108+
}
107109
scope.$evalAsync(function() {
108110
ngModelCtrl.$setViewValue(model);
109111
});

test/multiselect.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@ describe('<select multiple selectize>', function() {
8787
mousedownClickMouseup(selectize.$dropdown_content.find('[data-value="' + 2 + '"]'));
8888
assert.deepEqual(scope.selection, ['foo', 'baz']);
8989
});
90+
91+
it('should have the correct remaining options', function() {
92+
assert.strictEqual(selectize.$dropdown_content.children().length, scope.options.length - scope.selection.length);
93+
selectize.open();
94+
mousedownClickMouseup(selectize.$dropdown_content.find('[data-value="' + 2 + '"]'));
95+
timeout.flush();
96+
assert.strictEqual(selectize.$dropdown_content.children().length, scope.options.length - scope.selection.length);
97+
});
98+
99+
it('should not change the options on scope', function() {
100+
var options = angular.copy(scope.options);
101+
selectize.open();
102+
mousedownClickMouseup(selectize.$dropdown_content.find('[data-value="' + 2 + '"]'));
103+
timeout.flush();
104+
assert.deepEqual(scope.options, options);
105+
});
90106
});
91107

92108
describe('when a new option is added', function() {
@@ -213,6 +229,22 @@ describe('<select multiple selectize>', function() {
213229
mousedownClickMouseup(selectize.$dropdown_content.find('[data-value="' + 2 + '"]'));
214230
assert.deepEqual(scope.selection, ['guid1', 'guid3']);
215231
});
232+
233+
it('should have the correct remaining options', function() {
234+
assert.strictEqual(selectize.$dropdown_content.children().length, scope.options.length - scope.selection.length);
235+
selectize.open();
236+
mousedownClickMouseup(selectize.$dropdown_content.find('[data-value="' + 2 + '"]'));
237+
timeout.flush();
238+
assert.strictEqual(selectize.$dropdown_content.children().length, scope.options.length - scope.selection.length);
239+
});
240+
241+
it('should not change the options on scope', function() {
242+
var options = angular.copy(scope.options);
243+
selectize.open();
244+
mousedownClickMouseup(selectize.$dropdown_content.find('[data-value="' + 2 + '"]'));
245+
timeout.flush();
246+
assert.deepEqual(scope.options, options);
247+
});
216248
});
217249

218250
describe('when a new option is added', function() {

0 commit comments

Comments
 (0)