'
- ).append($selectAll).append($unselectAll);
+ let self = this;
+ let $rendered = decorated.call(this);
+
+ let $selectAll = $([
+ '',
+ ].join(''));
+
+ let $unselectAll = $([
+ '',
+ ].join(''));
+
+ let $btnContainer = $(
+ '
'
+ ).append($selectAll).append($unselectAll);
if (!this.$element.prop('multiple')) {
// this isn't a multi-select -> don't add the buttons!
return $rendered;
}
$rendered.find('.select2-dropdown').prepend($btnContainer);
+ // Select All button click
$selectAll.on('click', function() {
$rendered.find('.select2-results__option[aria-selected=false]').each(
function() {
+ // Note: With latest version we do not get data in the data attribute of a element
+ // Hence as per new logic we will fetch the data from the cache created by Select2.
+ let data = Utils.GetData($(this)[0], 'data');
self.trigger('select', {
- data: $(this).data('data'),
+ data: data,
});
}
);
self.trigger('close');
});
+ // Unselect All button click
$unselectAll.on('click', function() {
$rendered.find('.select2-results__option[aria-selected=true]').each(
function() {
+ let data = Utils.GetData($(this)[0], 'data');
self.trigger('unselect', {
- data: $(this).data('data'),
+ data: data,
});
}
);