1
0
mirror of synced 2024-12-01 17:16:02 +03:00

formatSelection() can now return html string, dom, or jquery object in both multi and single select. #188

This commit is contained in:
Igor Vaynberg 2012-07-14 23:35:57 +03:00
parent 1a4b523871
commit 6f973d6e40

View File

@ -1369,7 +1369,7 @@
this.selection this.selection
.find("span") .find("span")
.html(this.opts.formatSelection(data)); .empty().append(this.opts.formatSelection(data));
this.selection.removeClass("select2-default"); this.selection.removeClass("select2-default");
@ -1698,18 +1698,17 @@
addSelectedChoice: function (data) { addSelectedChoice: function (data) {
var choice, var choice,
id = this.id(data), id = this.id(data),
//span.formatSelection is only temporary
parts = ["<li class='select2-search-choice'>", parts = ["<li class='select2-search-choice'>",
"<span class='formatSelection'></span>", "<span class='select2-tmp'></span>",
"<a href='javascript:void(0)' class='select2-search-choice-close' tabindex='-1'></a>", "<a href='javascript:void(0)' class='select2-search-choice-close' tabindex='-1'></a>",
"</li>" "</li>"
], ],
val = this.getVal(); val = this.getVal();
choice = $(parts.join("")); choice = $(parts.join(""));
// replace span.formatSelection with the returned value of this.opts.formatSelection(data)
// allows the possibility to return jQuery objects with formatSelection choice.find('.select2-tmp').replaceWith(this.opts.formatSelection(data));
choice.find('.formatSelection').replaceWith(this.opts.formatSelection(data));
choice.find(".select2-search-choice-close") choice.find(".select2-search-choice-close")
.bind("click dblclick", this.bind(function (e) { .bind("click dblclick", this.bind(function (e) {
if (!this.enabled) return; if (!this.enabled) return;