I am using select2 (http://ivaynberg.github.io/select2/) for my tagging input. from the example in using select2 tagging the code is look like this.
$("#e12").select2({tags:["red", "green", "blue"]});
now my problem is how can I insert default value in my input just like in the page example in http://ivaynberg.github.io/select2/ at Tagging Support, the input has a default value of 'brown', 'red', & 'green'.
Updated version
Say you initialized your select like this:
Then use this 2 functions for triggering the change. (as seen in the official documentation)
Where "value1" and "value2" are IDs of the
option
elements of the select.You can initialize the Select2 control by providing a value for the hidden input:
And you can set the value of the Select2 control by passing an array to the 'val' method:
jsfiddle demo
For Select2 4.0 I had to add the data attribute to select2 and also set value and trigger change, like this: