Skip to content

Commit

Permalink
Fix for #438 + tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianreavis committed Jun 2, 2014
1 parent 337353a commit 8b33103
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,9 @@ $.extend(Selectize.prototype, {
if (!self.items.length) return;
self.$control.children(':not(input)').remove();
self.items = [];
self.lastQuery = null;
self.setCaret(0);
self.setActiveItem(null);
self.updatePlaceholder();
self.updateOriginalInput();
self.refreshState();
Expand Down Expand Up @@ -1924,7 +1926,7 @@ $.extend(Selectize.prototype, {
}

return html;
},
},

/**
* Clears the render cache for a template. If
Expand Down
37 changes: 36 additions & 1 deletion test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@
describe('clear()', function() {
var test;

before(function() {
beforeEach(function() {
test = setup_test('<select multiple>', {
valueField: 'value',
labelField: 'value',
Expand All @@ -433,6 +433,37 @@
items: ['1','2','3']
});
});
it('should empty "$activeItems" array', function() {
test.selectize.setActiveItem(test.selectize.getItem('1'));
expect(test.selectize.$activeItems.length).to.be.equal(1);
test.selectize.clear();
expect(test.selectize.$activeItems.length).to.be.equal(0);
});
it('should refresh option list (dropdown)', function(done) {
// test = setup_test('<select multiple>', {
// valueField: 'value',
// labelField: 'value',
// options: [
// {value: 0},
// {value: 1},
// {value: 2},
// {value: 3},
// ],
// items: ['1','2','3']
// });

test.selectize.focus();
window.setTimeout(function() {
test.selectize.clear();
test.selectize.focus();
window.setTimeout(function() {
expect(test.selectize.$dropdown_content.find('[data-value=1]').length).to.be.equal(1);
expect(test.selectize.$dropdown_content.find('[data-value=2]').length).to.be.equal(1);
expect(test.selectize.$dropdown_content.find('[data-value=3]').length).to.be.equal(1);
done();
}, 0);
}, 0);
});
it('should empty "items" array', function() {
test.selectize.clear();
expect(test.selectize.items.length).to.be.equal(0);
Expand All @@ -450,6 +481,10 @@
done();
}, 0);
});
it('should empty "items" array', function() {
test.selectize.clear();
expect(test.selectize.items.length).to.be.equal(0);
});
});

describe('search()', function() {
Expand Down

0 comments on commit 8b33103

Please sign in to comment.