Skip to content

Commit 8b7924f

Browse files
committed
Templating for selections
1 parent 98fb41b commit 8b7924f

10 files changed

Lines changed: 57 additions & 20 deletions

File tree

dist/js/select2.amd.full.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,9 @@ define('select2/selection/single',[
711711
};
712712

713713
SingleSelection.prototype.display = function (data) {
714-
return data.text;
714+
var template = this.options.get('templateSelection');
715+
716+
return template(data);
715717
};
716718

717719
SingleSelection.prototype.selectionContainer = function () {
@@ -788,7 +790,9 @@ define('select2/selection/multiple',[
788790
};
789791

790792
MultipleSelection.prototype.display = function (data) {
791-
return data.text;
793+
var template = this.options.get('templateSelection');
794+
795+
return template(data);
792796
};
793797

794798
MultipleSelection.prototype.selectionContainer = function () {
@@ -1625,6 +1629,9 @@ define('select2/defaults',[
16251629
language: ['select2/i18n/en'],
16261630
templateResult: function (result) {
16271631
return result.text;
1632+
},
1633+
templateSelection: function (selection) {
1634+
return selection.text;
16281635
}
16291636
};
16301637
};

dist/js/select2.amd.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,9 @@ define('select2/selection/single',[
711711
};
712712

713713
SingleSelection.prototype.display = function (data) {
714-
return data.text;
714+
var template = this.options.get('templateSelection');
715+
716+
return template(data);
715717
};
716718

717719
SingleSelection.prototype.selectionContainer = function () {
@@ -788,7 +790,9 @@ define('select2/selection/multiple',[
788790
};
789791

790792
MultipleSelection.prototype.display = function (data) {
791-
return data.text;
793+
var template = this.options.get('templateSelection');
794+
795+
return template(data);
792796
};
793797

794798
MultipleSelection.prototype.selectionContainer = function () {
@@ -1625,6 +1629,9 @@ define('select2/defaults',[
16251629
language: ['select2/i18n/en'],
16261630
templateResult: function (result) {
16271631
return result.text;
1632+
},
1633+
templateSelection: function (selection) {
1634+
return selection.text;
16281635
}
16291636
};
16301637
};

dist/js/select2.full.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10246,7 +10246,9 @@ define('select2/selection/single',[
1024610246
};
1024710247

1024810248
SingleSelection.prototype.display = function (data) {
10249-
return data.text;
10249+
var template = this.options.get('templateSelection');
10250+
10251+
return template(data);
1025010252
};
1025110253

1025210254
SingleSelection.prototype.selectionContainer = function () {
@@ -10323,7 +10325,9 @@ define('select2/selection/multiple',[
1032310325
};
1032410326

1032510327
MultipleSelection.prototype.display = function (data) {
10326-
return data.text;
10328+
var template = this.options.get('templateSelection');
10329+
10330+
return template(data);
1032710331
};
1032810332

1032910333
MultipleSelection.prototype.selectionContainer = function () {
@@ -11160,6 +11164,9 @@ define('select2/defaults',[
1116011164
language: ['select2/i18n/en'],
1116111165
templateResult: function (result) {
1116211166
return result.text;
11167+
},
11168+
templateSelection: function (selection) {
11169+
return selection.text;
1116311170
}
1116411171
};
1116511172
};

dist/js/select2.full.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/select2.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,9 @@ define('select2/selection/single',[
11391139
};
11401140

11411141
SingleSelection.prototype.display = function (data) {
1142-
return data.text;
1142+
var template = this.options.get('templateSelection');
1143+
1144+
return template(data);
11431145
};
11441146

11451147
SingleSelection.prototype.selectionContainer = function () {
@@ -1216,7 +1218,9 @@ define('select2/selection/multiple',[
12161218
};
12171219

12181220
MultipleSelection.prototype.display = function (data) {
1219-
return data.text;
1221+
var template = this.options.get('templateSelection');
1222+
1223+
return template(data);
12201224
};
12211225

12221226
MultipleSelection.prototype.selectionContainer = function () {
@@ -2053,6 +2057,9 @@ define('select2/defaults',[
20532057
language: ['select2/i18n/en'],
20542058
templateResult: function (result) {
20552059
return result.text;
2060+
},
2061+
templateSelection: function (selection) {
2062+
return selection.text;
20562063
}
20572064
};
20582065
};

dist/js/select2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/examples.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,13 +465,15 @@ <h2>Example code</h2>
465465
},
466466
templateResult: function (repo) {
467467
var markup = '<div class="row">' +
468-
'<div class="col-sm-1"><img src="' + repo.owner.avatar_url + '" style="max-width: 100%" /></div>' +
469-
'<div class="col-sm-11">' +
470-
'<div class="row">' +
471-
'<div class="col-sm-6">' + repo.full_name + '</div>' +
472-
'<div class="col-sm-3"><i class="fa fa-code-fork"></i> ' + repo.forks_count + '</div>' +
473-
'<div class="col-sm-3"><i class="fa fa-star"></i> ' + repo.stargazers_count + '</div>' +
474-
'</div>';
468+
'<div class="col-sm-1">' +
469+
'<img src="' + repo.owner.avatar_url + '" style="max-width: 100%" />' +
470+
'</div>' +
471+
'<div class="col-sm-11">' +
472+
'<div class="row">' +
473+
'<div class="col-sm-6">' + repo.full_name + '</div>' +
474+
'<div class="col-sm-3"><i class="fa fa-code-fork"></i> ' + repo.forks_count + '</div>' +
475+
'<div class="col-sm-3"><i class="fa fa-star"></i> ' + repo.stargazers_count + '</div>' +
476+
'</div>';
475477

476478
if (repo.description) {
477479
markup += '<div>' + repo.description + '</div>';

src/js/select2/defaults.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ define([
116116
language: ['select2/i18n/en'],
117117
templateResult: function (result) {
118118
return result.text;
119+
},
120+
templateSelection: function (selection) {
121+
return selection.text;
119122
}
120123
};
121124
};

src/js/select2/selection/multiple.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ define([
5252
};
5353

5454
MultipleSelection.prototype.display = function (data) {
55-
return data.text;
55+
var template = this.options.get('templateSelection');
56+
57+
return template(data);
5658
};
5759

5860
MultipleSelection.prototype.selectionContainer = function () {

src/js/select2/selection/single.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ define([
9090
};
9191

9292
SingleSelection.prototype.display = function (data) {
93-
return data.text;
93+
var template = this.options.get('templateSelection');
94+
95+
return template(data);
9496
};
9597

9698
SingleSelection.prototype.selectionContainer = function () {

0 commit comments

Comments
 (0)