Skip to content

Commit

Permalink
Merge c04f48f into 5b06be3
Browse files Browse the repository at this point in the history
  • Loading branch information
giero committed Apr 8, 2019
2 parents 5b06be3 + c04f48f commit 52cc802
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,7 @@ $.extend(Selectize.prototype, {
i = self.items.indexOf(value);

if (i !== -1) {
self.trigger('item_before_remove', value, $item);
$item.remove();
if ($item.hasClass('active')) {
idx = self.$activeItems.indexOf($item[0]);
Expand Down
19 changes: 19 additions & 0 deletions test/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,25 @@ describe('Events', function() {
});
});

describe('item_before_remove', function() {
it('should be triggered', function(done) {
var test = setup_test('<select multiple><option value="a" selected></option><option value="b" selected></option><option value="c"></option></select>', {});
test.selectize.on('item_before_remove', function() {
done();
});
test.selectize.removeItem('a');
});
it('should contain item\'s value and element', function(done) {
var test = setup_test('<select multiple><option value="a" selected></option><option value="b" selected></option><option value="c"></option></select>', {});
test.selectize.on('item_before_remove', function(value, $item) {
expect(value).to.be.equal('b');
assert.equal($item.length, 1);
done();
});
test.selectize.removeItem('b');
});
});

describe('item_remove', function() {
it('should be triggered', function(done) {
var test = setup_test('<select multiple><option value="a" selected></option><option value="b" selected></option><option value="c"></option></select>', {});
Expand Down

0 comments on commit 52cc802

Please sign in to comment.