From 6f973d6e406a27ed9bd62d5968113bca56e1e519 Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Sat, 14 Jul 2012 23:35:57 +0300 Subject: [PATCH] formatSelection() can now return html string, dom, or jquery object in both multi and single select. #188 --- select2.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/select2.js b/select2.js index a078b9ff..5c4c14e5 100755 --- a/select2.js +++ b/select2.js @@ -1369,7 +1369,7 @@ this.selection .find("span") - .html(this.opts.formatSelection(data)); + .empty().append(this.opts.formatSelection(data)); this.selection.removeClass("select2-default"); @@ -1698,18 +1698,17 @@ addSelectedChoice: function (data) { var choice, id = this.id(data), - //span.formatSelection is only temporary + parts = ["
  • ", - "", + "", "", "
  • " ], val = this.getVal(); 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('.formatSelection').replaceWith(this.opts.formatSelection(data)); + + choice.find('.select2-tmp').replaceWith(this.opts.formatSelection(data)); choice.find(".select2-search-choice-close") .bind("click dblclick", this.bind(function (e) { if (!this.enabled) return;