wryrych
wryrych

Reputation: 1765

how to set values when Select2 is ready?

Does Select2 have any onLoad event so that I can set some default value? Now I resorted to some ugly trick after Select2 is added to the Dom with the help of Ember's didInsertElement:

`setTimeout(function() {$select.select2('val', id).trigger('change'), 500});

I'm pretty sure there is a better solution out there :)

Upvotes: 2

Views: 1658

Answers (1)

coder
coder

Reputation: 701

Try this, it may help you,

$(document).ready(function() 
{
  $("<option value='0'>Default</option>").insertBefore("option:nth-child(1)");
});

Upvotes: 1

Related Questions