Skip to content

Commit 1e44ab7

Browse files
committed
Added the element reference in the data
This also fixes `_normalizeItem` for cases where `text` doesn't exist, so it doesn't clobber the item.
1 parent 33809f1 commit 1e44ab7

7 files changed

Lines changed: 32 additions & 32 deletions

File tree

dist/js/select2.amd.full.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,7 @@ define('select2/data/select',[
22392239
var $option = $(option);
22402240

22412241
var normalizedData = this._normalizeItem(data);
2242+
normalizedData.element = option;
22422243

22432244
// Override the option's data with the combined data
22442245
$.data(option, 'data', normalizedData);
@@ -2283,19 +2284,18 @@ define('select2/data/select',[
22832284
}
22842285

22852286
data = this._normalizeItem(data);
2287+
data.element = $option[0];
22862288

22872289
$.data($option[0], 'data', data);
22882290

22892291
return data;
22902292
};
22912293

22922294
SelectAdapter.prototype._normalizeItem = function (item) {
2293-
if (item.text == null) {
2294-
item = {
2295-
id: item,
2296-
text: item
2297-
};
2298-
}
2295+
$.extend(item, {
2296+
id: item,
2297+
text: item
2298+
});
22992299

23002300
var defaults = {
23012301
selected: false,

dist/js/select2.amd.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,7 @@ define('select2/data/select',[
22392239
var $option = $(option);
22402240

22412241
var normalizedData = this._normalizeItem(data);
2242+
normalizedData.element = option;
22422243

22432244
// Override the option's data with the combined data
22442245
$.data(option, 'data', normalizedData);
@@ -2283,19 +2284,18 @@ define('select2/data/select',[
22832284
}
22842285

22852286
data = this._normalizeItem(data);
2287+
data.element = $option[0];
22862288

22872289
$.data($option[0], 'data', data);
22882290

22892291
return data;
22902292
};
22912293

22922294
SelectAdapter.prototype._normalizeItem = function (item) {
2293-
if (item.text == null) {
2294-
item = {
2295-
id: item,
2296-
text: item
2297-
};
2298-
}
2295+
$.extend(item, {
2296+
id: item,
2297+
text: item
2298+
});
22992299

23002300
var defaults = {
23012301
selected: false,

dist/js/select2.full.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11774,6 +11774,7 @@ define('select2/data/select',[
1177411774
var $option = $(option);
1177511775

1177611776
var normalizedData = this._normalizeItem(data);
11777+
normalizedData.element = option;
1177711778

1177811779
// Override the option's data with the combined data
1177911780
$.data(option, 'data', normalizedData);
@@ -11818,19 +11819,18 @@ define('select2/data/select',[
1181811819
}
1181911820

1182011821
data = this._normalizeItem(data);
11822+
data.element = $option[0];
1182111823

1182211824
$.data($option[0], 'data', data);
1182311825

1182411826
return data;
1182511827
};
1182611828

1182711829
SelectAdapter.prototype._normalizeItem = function (item) {
11828-
if (item.text == null) {
11829-
item = {
11830-
id: item,
11831-
text: item
11832-
};
11833-
}
11830+
$.extend(item, {
11831+
id: item,
11832+
text: item
11833+
});
1183411834

1183511835
var defaults = {
1183611836
selected: false,

dist/js/select2.full.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.

dist/js/select2.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,6 +2667,7 @@ define('select2/data/select',[
26672667
var $option = $(option);
26682668

26692669
var normalizedData = this._normalizeItem(data);
2670+
normalizedData.element = option;
26702671

26712672
// Override the option's data with the combined data
26722673
$.data(option, 'data', normalizedData);
@@ -2711,19 +2712,18 @@ define('select2/data/select',[
27112712
}
27122713

27132714
data = this._normalizeItem(data);
2715+
data.element = $option[0];
27142716

27152717
$.data($option[0], 'data', data);
27162718

27172719
return data;
27182720
};
27192721

27202722
SelectAdapter.prototype._normalizeItem = function (item) {
2721-
if (item.text == null) {
2722-
item = {
2723-
id: item,
2724-
text: item
2725-
};
2726-
}
2723+
$.extend(item, {
2724+
id: item,
2725+
text: item
2726+
});
27272727

27282728
var defaults = {
27292729
selected: false,

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.

src/js/select2/data/select.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ define([
146146
var $option = $(option);
147147

148148
var normalizedData = this._normalizeItem(data);
149+
normalizedData.element = option;
149150

150151
// Override the option's data with the combined data
151152
$.data(option, 'data', normalizedData);
@@ -190,19 +191,18 @@ define([
190191
}
191192

192193
data = this._normalizeItem(data);
194+
data.element = $option[0];
193195

194196
$.data($option[0], 'data', data);
195197

196198
return data;
197199
};
198200

199201
SelectAdapter.prototype._normalizeItem = function (item) {
200-
if (item.text == null) {
201-
item = {
202-
id: item,
203-
text: item
204-
};
205-
}
202+
$.extend(item, {
203+
id: item,
204+
text: item
205+
});
206206

207207
var defaults = {
208208
selected: false,

0 commit comments

Comments
 (0)