ivaynberg/select2 — pull request #1690 by evangun (2013-09-05 16:39:44+00:00)
Title: Edit the default initSelection function to pass all tag properties

The function will now pass all properties of the objects passed as tags to the constructor, not just the "id" and "text" properties. Because a tag is not always just an id and a text, just like when you provide the items with the "data" object instead.

This makes sure these properties are always available at the runtime of formatSelection() or formatResult(), which is not currently the case when the field is repopulated on a triggered "change" event.

It would allow me to do this without overriding initSelection() in the constructor :

$el.select2({
...,
tags: [{
//id
id: 1,
//the string that will matched against the user's query
text: 'martin smith greatmartin@provider.com'
//the label of the item that will be shown if this tag is selected
label: 'M. Smith',
}],
formatSelection: function(object, container){
return object.label || object.text;
});