Skip to content

Commit e919b24

Browse files
committed
Added clearOptions() method (selectize#22).
1 parent 8c3ea2f commit e919b24

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

examples/api.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ <h2>API</h2>
2828
</div>
2929
<div class="buttons">
3030
<input type="button" value="clear()" id="button-clear">
31+
<input type="button" value="clearOptions()" id="button-clearoptions">
3132
<input type="button" value="addOption()" id="button-addoption">
3233
<input type="button" value="addItem()" id="button-additem">
3334
<input type="button" value="setValue()" id="button-setvalue">
@@ -54,6 +55,10 @@ <h2>API</h2>
5455
control.clear();
5556
});
5657

58+
$('#button-clearoptions').on('click', function() {
59+
control.clearOptions();
60+
});
61+
5762
$('#button-addoption').on('click', function() {
5863
control.addOption(4, {
5964
id: 4,

src/selectize.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,11 @@ Selectize.prototype.refreshOptions = function(triggerDropdown) {
903903
* the options list dropdown (use `refreshOptions`
904904
* for that).
905905
*
906+
* Usage:
907+
*
908+
* this.addOption(value, data)
909+
* this.addOption(data)
910+
*
906911
* @param {string} value
907912
* @param {object} data
908913
*/
@@ -949,7 +954,7 @@ Selectize.prototype.updateOption = function(value, data) {
949954
};
950955

951956
/**
952-
* Removes an option.
957+
* Removes a single option.
953958
*
954959
* @param {string} value
955960
*/
@@ -962,6 +967,17 @@ Selectize.prototype.removeOption = function(value) {
962967
this.removeItem(value);
963968
};
964969

970+
/**
971+
* Clears all options.
972+
*/
973+
Selectize.prototype.clearOptions = function() {
974+
this.userOptions = {};
975+
this.options = {};
976+
this.lastQuery = null;
977+
this.trigger('onOptionClear');
978+
this.clear();
979+
};
980+
965981
/**
966982
* Returns the jQuery element of the option
967983
* matching the given value.
@@ -1519,6 +1535,7 @@ Selectize.defaults = {
15191535
onClear : null, // function() { ... }
15201536
onOptionAdd : null, // function(value, data) { ... }
15211537
onOptionRemove : null, // function(value) { ... }
1538+
onOptionClear : null, // function() { ... }
15221539
onDropdownOpen : null, // function($dropdown) { ... }
15231540
onDropdownClose : null, // function($dropdown) { ... }
15241541
onType : null, // function(str) { ... }

0 commit comments

Comments
 (0)