Skip to content

Commit b8ce36a

Browse files
committed
Add text function for formatResult and formatSelection
1 parent d487fc5 commit b8ce36a

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

select2.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ the specific language governing permissions and limitations under the Apache Lic
459459
* the text.
460460
*/
461461
function local(options) {
462+
462463
var data = options, // data elements
463464
dataText,
464465
tmp,
@@ -3386,11 +3387,11 @@ the specific language governing permissions and limitations under the Apache Lic
33863387
dropdownCssClass: "",
33873388
formatResult: function(result, container, query, escapeMarkup) {
33883389
var markup=[];
3389-
markMatch(result.text, query.term, markup, escapeMarkup);
3390+
markMatch(this.text(result), query.term, markup, escapeMarkup);
33903391
return markup.join("");
33913392
},
33923393
formatSelection: function (data, container, escapeMarkup) {
3393-
return data ? escapeMarkup(data.text) : undefined;
3394+
return data ? escapeMarkup(this.text(data)) : undefined;
33943395
},
33953396
sortResults: function (results, container, query) {
33963397
return results;
@@ -3409,6 +3410,17 @@ the specific language governing permissions and limitations under the Apache Lic
34093410
maximumInputLength: null,
34103411
maximumSelectionSize: 0,
34113412
id: function (e) { return e == undefined ? null : e.id; },
3413+
text: function (e) {
3414+
if (e && this.data && this.data.text) {
3415+
if ($.isFunction(this.data.text)) {
3416+
return this.data.text(e);
3417+
} else {
3418+
return e[this.data.text];
3419+
}
3420+
} else {
3421+
return e.text;
3422+
}
3423+
},
34123424
matcher: function(term, text) {
34133425
return stripDiacritics(''+text).toUpperCase().indexOf(stripDiacritics(''+term).toUpperCase()) >= 0;
34143426
},

0 commit comments

Comments
 (0)