Hi,
i need to add a “Select All” button in a select2 multiple select, the functionality should be to select all the current results in the dropdown.
I tried to follow the example https://jsfiddle.net/hula_zell/50v60cm6/1/, but apparently the result items don’t carry the correct data attribute in this case, in particular, this part of the example doesn’t work:
// Get all results that aren't selected
$results.each(function() {
var $result = $(this);
// Get the data object for it
var data = $result.data('data');
// Trigger the select event
self.trigger('select', {
data: data
});
});
the $result.data(‘data’) just returns undefined, calling $result.data() returns for example { select2Id: 13 }. Is there a way to set the actual results from this information?
Note: based on comment: https://github.com/select2/select2/issues/195#issuecomment-401532685, moving here because the forum seems to be a better place to discuss issues like this.
Thanks in advance!