clearOptions should not clear items
The clearOptions() method results in the clear() method also being called. Given the logical distinction between "options" and "items" this seems incorrect. The behavior also prevents (unless I'm missing another approach) the use case of providing a new set of options for each item, as follows: $('#select-state').selectize({ load: function(query, callback){ this.clearOptions(); //fetch the new options } });
But couldn't your fix clear the input-field if the query was really fast or really slow? I use the onType to clear the query cache. And more or less the same code for onClear and onItemRemove. This code is for an older version of selectize, so you might not need all the lines anymore and could probably be optimized even more.
$('#select-state').selectize({
onType: function(){
ajaxquery && ajaxquery.abort();
this.$input[0].selectize.renderCache = {};
this.$input[0].selectize.clearOptions();
this.$input[0].selectize.refreshOptions(true);
},
load: function(query, callback) {
if (!query.length) return callback();
ajaxquery && ajaxquery.abort();
ajaxquery = $.ajax({
url: '/?q=' + encodeURIComponent(query),
type: 'GET',
dataType: 'json',
error: function() {
callback();
},
success: function(res) {
callback(res);
}
});
}
});
This is nonsense why it's still open. You should just remove .clear() at the end of the function and it just works as expected.
Has this issue been fixed? if not then how can we implement clearOptions with a hacky way so that our options will be cleared without being cleared the selected input option? If Somebody can help then it would be really appreciated.
According to this changelog: Fixed bug making clearOptions function. Now it doesn't remove already selected options.
(thanks @caseymct - #1079)
But it doesn't seem to work. Also, silent is implemented and doesn't see to work too.
I can confirm for silent. Not working for add item
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days
This is wrong proposition. clearOptions must call clear otherwise data will be inconsistent.
For example you have list 1,2, user selected 7. Is this expected? No, because there is no 7 on the list.
Same with clearOptions. If options are cleared, you can choose nothing, thus selected list also must be cleared.