I need to change the maximumSelectionLength option dynamically in multiple select2 v4.0.0.
For example, if the user chooses 'ALL' value I need to set maximumSelectionLength to 1, in order not to allow user to choose other option than 'ALL', but if the user chooses some other value, I need to keep maximumSelectionLength = 0 (Infinity).
I tried this code:
// select2 initilaization
$('#selector').select2({some options and ajax call})
}).change(function(e) {
$(this).data('select2').options.options.maximumSelectionLength = 1;
console.log($(this).data('select2').options.options);
});;
In console.log I can see the options is changed, but it is not applied to the select2 options.
Knowing that in select2 v3.5.0 I used to this and it was working fine.
I used to write this code:
$(this).data('select2').opts.maximumSelectionSize = 1;
Please help regarding this.
Thank you.