Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select2-jquery: How to set maximumselectionsize dynamically

I've a requirement where I'll decide Max selections to be allowed in select2 ui.How can I do that. I tried by

$('#ChnageLnk').on('click',function(){
$('#SelectD').select2({maximumselectionsize :1});
});
like image 401
Mahesh Reddy Avatar asked Feb 26 '26 21:02

Mahesh Reddy


2 Answers

Please, note that since version 4.0 of select2 they have changed maximumSelectionSize to maximumSelectionLength.

You can find more in this question: maximumSelectionSize isn't working in Select2

like image 164
ivan.mylyanyk Avatar answered Mar 01 '26 10:03

ivan.mylyanyk


Edit

Sorry - just checked. The option should not be all lowercase - it should be camel case like so:

$('#ChnageLnk').on('click',function(){
   $('#SelectD').select2({ maximumSelectionSize: 1 });
});

Fiddle here.

like image 44
mccannf Avatar answered Mar 01 '26 10:03

mccannf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!