Reputation: 330
I want to be able to select all options or 1 optgroup in select built with TomSelect.
There is no option to select all. I reviewed documentation and could not find any info in github.
Upvotes: 1
Views: 1379
Reputation: 78
I also had this problem today. You can do this like that to select all options:
var tomSelect = new TomSelect(...)
$('#check-all').click(function(event) {
const allValues = tomSelect.options;
var valuesToSelect = Object.keys(allValues).map(function(key) {
return allValues[key].value;
});
tomSelect.setValue(valuesToSelect); // Set all values to select them
});
Also this to uncheck all:
$('#uncheck-all').click(function(event) {
event.preventDefault();
tomSelect.setValue([]); // Set all values to empty to uncheck all
});
Upvotes: 2