From b8ce36a65e46a00a0bfddc499eb7ba84829de461 Mon Sep 17 00:00:00 2001 From: Santi Albo Date: Wed, 28 May 2014 18:13:26 +0100 Subject: [PATCH 1/2] Add text function for formatResult and formatSelection --- select2.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/select2.js b/select2.js index cf54469a..85ddf94f 100644 --- a/select2.js +++ b/select2.js @@ -459,6 +459,7 @@ the specific language governing permissions and limitations under the Apache Lic * the text. */ function local(options) { + var data = options, // data elements dataText, tmp, @@ -3386,11 +3387,11 @@ the specific language governing permissions and limitations under the Apache Lic dropdownCssClass: "", formatResult: function(result, container, query, escapeMarkup) { var markup=[]; - markMatch(result.text, query.term, markup, escapeMarkup); + markMatch(this.text(result), query.term, markup, escapeMarkup); return markup.join(""); }, formatSelection: function (data, container, escapeMarkup) { - return data ? escapeMarkup(data.text) : undefined; + return data ? escapeMarkup(this.text(data)) : undefined; }, sortResults: function (results, container, query) { return results; @@ -3409,6 +3410,17 @@ the specific language governing permissions and limitations under the Apache Lic maximumInputLength: null, maximumSelectionSize: 0, id: function (e) { return e == undefined ? null : e.id; }, + text: function (e) { + if (e && this.data && this.data.text) { + if ($.isFunction(this.data.text)) { + return this.data.text(e); + } else { + return e[this.data.text]; + } + } else { + return e.text; + } + }, matcher: function(term, text) { return stripDiacritics(''+text).toUpperCase().indexOf(stripDiacritics(''+term).toUpperCase()) >= 0; }, From db86f195526a382cb37d0ae068fed29b15ea504c Mon Sep 17 00:00:00 2001 From: Santi Albo Date: Wed, 28 May 2014 18:17:31 +0100 Subject: [PATCH 2/2] Remove added line --- select2.js | 1 - 1 file changed, 1 deletion(-) diff --git a/select2.js b/select2.js index 85ddf94f..2d2b3cd0 100644 --- a/select2.js +++ b/select2.js @@ -459,7 +459,6 @@ the specific language governing permissions and limitations under the Apache Lic * the text. */ function local(options) { - var data = options, // data elements dataText, tmp,