When I set value of selected element through code by using select2('val', 'some-val'), change event is not triggered.
In documentation it is stated that change event will be triggered when user changes value (I suppose that means by user interaction), but it would also be useful if this event would be triggered when value is changed through code (so that added and removed properties of event arguments could be used).
From documentation:
"change event is triggered on the original element whenever its value is changed by the user"
select2('val', 'some-val', true)
For those who are wondering where this third parameter is specific in the documentation:
It's specified under val as triggerChange, and it's set to false by default.
Thanks @kevin-brown and @ivaynberg, when i was using:
$('#my-element').select2("val', {id: 'EU', text: 'Europe'}).trigger('change');
The text was coming in blank, so i changed to:
$('#my-element').select2("val', {id: 'EU', text: 'Europe'}, true);
Then the text is loaded normally. My current Select2 version is 3.5.2.
Most helpful comment
select2('val', 'some-val', true)