You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 18, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 18, 2026. It is now read-only.
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.
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.
Imho, this is bad design - method is called clearOptions and that is exactly what is expected from the method to do.
It shouldn't delete any already selected items.
For example in my case - I need to delete all options all the time, because I am calling backend with every pressed letter on keyboard. Then user selects what they need and I close options and delete them - ready for next query. When they select everything they need, they submit results with button. In version 0.12.6 this worked quite well.
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.
Its true what he said, remove the clear and use it like this example:
it works like butter 👍
// Functie om gebruikers op te halen en dropdown te vullen met behulp van Selectize
function loadUsers(selectedEmails = []) {
Fliplet.DataSources.connect(usersDataSourceId)
.then(connection => connection.find())
.then(users => {
if (!users.length) {
console.warn('Geen gebruikers gevonden.');
return;
}
const emailSelect = document.getElementById("emailSelect");
// Controleer of Selectize al is geïnitialiseerd en haal de controle op
let selectizeControl = $(emailSelect)[0].selectize;
if (selectizeControl) {
// Als Selectize al bestaat, maak dan de huidige selectie leeg
selectizeControl.clear(); // Wis de geselecteerde items zonder de opties te wissen
} else {
// Initialiseer Selectize als het nog niet bestaat
$(emailSelect).selectize({
plugins: ['remove_button'],
delimiter: ',',
persist: false,
create: false,
sortField: 'text'
});
// Haal nu de selectize instance op
selectizeControl = $(emailSelect)[0].selectize;
}
// Voeg opties toe aan de select dropdown
selectizeControl.clearOptions(); // Zorg ervoor dat er geen dubbele opties komen te staan
users.forEach(user => {
if (user.data && user.data.Email && user.data.Email.trim() !== "") {
selectizeControl.addOption({
value: user.data.Email,
text: user.data.Email
});
}
});
console.log('Gebruikers succesvol geladen en dropdown bijgewerkt met Selectize.');
// Selecteer bestaande e-mails indien aanwezig
if (selectedEmails.length > 0) {
selectedEmails.forEach(email => {
selectizeControl.addItem(email);
});
}
})
.catch(error => {
console.error('Fout bij het laden van gebruikers:', error);
});
Due to a merge conflict between two incompatible feature requests, we now have the worst of both worlds: clearOptions() specifically does not remove currently-selected options; but does clear the selection. See #2146 for a more complete explanation.
edit: in my humble opinion there should absolutely be an option to keep all selected items but clear all options which are not selected
// do not use clearOptions here, as it also clears all selected items..
// also: currently there is a bug and clearOptions does not remove the options, but all selected items
//this.clearOptions();
// list of options to keep because they are selected
var optionsToKeep = [];
this.items.forEach((item) => {
optionsToKeep.push(this.options[item]);
});
// list of options to remove
var optionsToRemove = [];
for (var [key, value] of Object.entries(this.options)) {
if (!optionsToKeep.includes(value)){
optionsToRemove.push(value);
}
}
// remove options
optionsToRemove.forEach((option) => {
this.removeOption(option.value, true);
});
Activity
flamber commentedon Nov 3, 2014
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.
dresende commentedon Sep 25, 2018
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.jicihome commentedon Dec 30, 2020
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.
jicihome commentedon Mar 30, 2021
I can confirm for silent. Not working for add item
github-actions commentedon Jun 29, 2021
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
KES777 commentedon Jun 21, 2023
This is wrong proposition.
clearOptionsmust callclearotherwise 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 listalso must be cleared.suchoss commentedon Jul 12, 2024
Imho, this is bad design - method is called
clearOptionsand that is exactly what is expected from the method to do.It shouldn't delete any already selected items.
For example in my case - I need to delete all options all the time, because I am calling backend with every pressed letter on keyboard. Then user selects what they need and I close options and delete them - ready for next query. When they select everything they need, they submit results with button. In version
0.12.6this worked quite well.jthakilla9 commentedon Oct 25, 2024
Its true what he said, remove the clear and use it like this example:
it works like butter 👍
// Functie om gebruikers op te halen en dropdown te vullen met behulp van Selectize
function loadUsers(selectedEmails = []) {
Fliplet.DataSources.connect(usersDataSourceId)
.then(connection => connection.find())
.then(users => {
if (!users.length) {
console.warn('Geen gebruikers gevonden.');
return;
}
}
dvg-p4 commentedon Nov 12, 2024
Due to a merge conflict between two incompatible feature requests, we now have the worst of both worlds:
clearOptions()specifically does not remove currently-selected options; but does clear the selection. See #2146 for a more complete explanation.kunibertgangnam commentedon May 30, 2025
here is how i worked around this issue
edit: in my humble opinion there should absolutely be an option to keep all selected items but clear all options which are not selected