Skip to content

Commit 9315721

Browse files
committed
Merge pull request select2#2415 from santialbo/text-function
Add text function for formatResult and formatSelection
2 parents 7505bb6 + db86f19 commit 9315721

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

select2.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,11 +3420,11 @@ the specific language governing permissions and limitations under the Apache Lic
34203420
dropdownCssClass: "",
34213421
formatResult: function(result, container, query, escapeMarkup) {
34223422
var markup=[];
3423-
markMatch(result.text, query.term, markup, escapeMarkup);
3423+
markMatch(this.text(result), query.term, markup, escapeMarkup);
34243424
return markup.join("");
34253425
},
34263426
formatSelection: function (data, container, escapeMarkup) {
3427-
return data ? escapeMarkup(data.text) : undefined;
3427+
return data ? escapeMarkup(this.text(data)) : undefined;
34283428
},
34293429
sortResults: function (results, container, query) {
34303430
return results;
@@ -3436,6 +3436,17 @@ the specific language governing permissions and limitations under the Apache Lic
34363436
maximumInputLength: null,
34373437
maximumSelectionSize: 0,
34383438
id: function (e) { return e == undefined ? null : e.id; },
3439+
text: function (e) {
3440+
if (e && this.data && this.data.text) {
3441+
if ($.isFunction(this.data.text)) {
3442+
return this.data.text(e);
3443+
} else {
3444+
return e[this.data.text];
3445+
}
3446+
} else {
3447+
return e.text;
3448+
}
3449+
},
34393450
matcher: function(term, text) {
34403451
return stripDiacritics(''+text).toUpperCase().indexOf(stripDiacritics(''+term).toUpperCase()) >= 0;
34413452
},

0 commit comments

Comments
 (0)