Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ var selectize = $select[0].selectize;
<td valign="top"><code>isFull()</code></td>
<td valign="top">Returns whether or not the user can select more items.</td>
</tr>
<tr>
<td valign="top"><code>clearCache(template)</code></td>
<td valign="top">Clears the render cache. Takes an optional template argument (e.g. "option", "item") to clear only that cache.</td>
</tr>
</table>

### Related Objects
Expand Down
17 changes: 17 additions & 0 deletions src/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,23 @@ $.extend(Selectize.prototype, {
}

return html;
},

/**
* Clears the render cache for a template. If
* no template is given, clears all render
* caches.
*
* @param {string} templateName
*/
clearCache: function(templateName) {
var self = this;
if (typeof templateName === 'undefined') {
self.renderCache = {};
} else {
delete self.renderCache[templateName];
}
}


});
35 changes: 35 additions & 0 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,41 @@
});
});

describe('clearCache()', function() {
var test;

before(function() {
test = setup_test('<select multiple>', {
valueField: 'value',
labelField: 'value',
options: [
{value: 0},
{value: 1},
{value: 2},
{value: 3},
],
items: ['1','2','3']
});
test.selectize.advanceSelection(1);
test.selectize.refreshOptions(true);
test.selectize.refreshItems();
});
it('should clear the whole renderCache', function () {
expect($.isEmptyObject(test.selectize.renderCache)).to.be.equal(false);
test.selectize.clearCache();
expect($.isEmptyObject(test.selectize.renderCache)).to.be.equal(true);
});
it('should allow clearing just one template type from the renderCache', function () {
test.selectize.render('item', test.selectize.options[0]);
test.selectize.refreshOptions();
expect($.isEmptyObject(test.selectize.renderCache['option'])).to.be.equal(false);
expect($.isEmptyObject(test.selectize.renderCache['item'])).to.be.equal(false);
test.selectize.clearCache('option');
expect($.isEmptyObject(test.selectize.renderCache['option'])).to.be.equal(true);
expect($.isEmptyObject(test.selectize.renderCache['item'])).to.be.equal(false);
});
});

});

})();