Skip to content

Commit ad9fac4

Browse files
committed
make sure data() returns null instead of undefined when unset. this will prevent chaining which may seem weid. fixes select2#230
1 parent de0d11a commit ad9fac4

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

select2.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,6 @@
12811281
initSelection: function () {
12821282
var selected;
12831283
if (this.opts.element.val() === "") {
1284-
this.updateSelection({id: "", text: ""});
12851284
this.close();
12861285
this.setPlaceholder();
12871286
} else {
@@ -1322,11 +1321,8 @@
13221321
// check for a first blank option if attached to a select
13231322
if (this.select && this.select.find("option:first").text() !== "") return;
13241323

1325-
if (typeof(placeholder) === "object") {
1326-
this.updateSelection(placeholder);
1327-
} else {
1328-
this.selection.find("span").html(placeholder);
1329-
}
1324+
this.selection.find("span").html(placeholder);
1325+
13301326
this.selection.addClass("select2-default");
13311327

13321328
this.selection.find("abbr").hide();
@@ -1431,8 +1427,12 @@
14311427

14321428
// single
14331429
data: function(value) {
1430+
var data;
1431+
14341432
if (arguments.length === 0) {
1435-
return this.selection.data("select2-data");
1433+
data = this.selection.data("select2-data");
1434+
if (data == undefined) data = null;
1435+
return data;
14361436
} else {
14371437
if (!value || value === "") {
14381438
this.clear();

0 commit comments

Comments
 (0)