Skip to content

Commit 6f973d6

Browse files
committed
formatSelection() can now return html string, dom, or jquery object in both multi and single select. select2#188
1 parent 1a4b523 commit 6f973d6

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

select2.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@
13691369

13701370
this.selection
13711371
.find("span")
1372-
.html(this.opts.formatSelection(data));
1372+
.empty().append(this.opts.formatSelection(data));
13731373

13741374
this.selection.removeClass("select2-default");
13751375

@@ -1698,18 +1698,17 @@
16981698
addSelectedChoice: function (data) {
16991699
var choice,
17001700
id = this.id(data),
1701-
//span.formatSelection is only temporary
1701+
17021702
parts = ["<li class='select2-search-choice'>",
1703-
"<span class='formatSelection'></span>",
1703+
"<span class='select2-tmp'></span>",
17041704
"<a href='javascript:void(0)' class='select2-search-choice-close' tabindex='-1'></a>",
17051705
"</li>"
17061706
],
17071707
val = this.getVal();
17081708

17091709
choice = $(parts.join(""));
1710-
// replace span.formatSelection with the returned value of this.opts.formatSelection(data)
1711-
// allows the possibility to return jQuery objects with formatSelection
1712-
choice.find('.formatSelection').replaceWith(this.opts.formatSelection(data));
1710+
1711+
choice.find('.select2-tmp').replaceWith(this.opts.formatSelection(data));
17131712
choice.find(".select2-search-choice-close")
17141713
.bind("click dblclick", this.bind(function (e) {
17151714
if (!this.enabled) return;

0 commit comments

Comments
 (0)