Is there any way to load select2 to a default value without triggering the change event?
Currently, I am doing:
$('#mylist').val(2).trigger("change");
But this creates a delay where the user will at first see one option and then it will change, which is quite an annoyance.
I know I'm really late to answer this question. I was facing the same issue. But doing a bit of research I found a solution that works like a charm.
You can set an option using below code
$("#mylist").val(2).trigger('change.select2');
This solution will not trigger the main change event but sets the option to the select2
component.
Hope that helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With