make sure data() returns null instead of undefined when unset. this will prevent chaining which may seem weid. fixes #230
This commit is contained in:
parent
de0d11a82b
commit
ad9fac45ae
12
select2.js
12
select2.js
@ -1281,7 +1281,6 @@
|
|||||||
initSelection: function () {
|
initSelection: function () {
|
||||||
var selected;
|
var selected;
|
||||||
if (this.opts.element.val() === "") {
|
if (this.opts.element.val() === "") {
|
||||||
this.updateSelection({id: "", text: ""});
|
|
||||||
this.close();
|
this.close();
|
||||||
this.setPlaceholder();
|
this.setPlaceholder();
|
||||||
} else {
|
} else {
|
||||||
@ -1322,11 +1321,8 @@
|
|||||||
// check for a first blank option if attached to a select
|
// check for a first blank option if attached to a select
|
||||||
if (this.select && this.select.find("option:first").text() !== "") return;
|
if (this.select && this.select.find("option:first").text() !== "") return;
|
||||||
|
|
||||||
if (typeof(placeholder) === "object") {
|
|
||||||
this.updateSelection(placeholder);
|
|
||||||
} else {
|
|
||||||
this.selection.find("span").html(placeholder);
|
this.selection.find("span").html(placeholder);
|
||||||
}
|
|
||||||
this.selection.addClass("select2-default");
|
this.selection.addClass("select2-default");
|
||||||
|
|
||||||
this.selection.find("abbr").hide();
|
this.selection.find("abbr").hide();
|
||||||
@ -1431,8 +1427,12 @@
|
|||||||
|
|
||||||
// single
|
// single
|
||||||
data: function(value) {
|
data: function(value) {
|
||||||
|
var data;
|
||||||
|
|
||||||
if (arguments.length === 0) {
|
if (arguments.length === 0) {
|
||||||
return this.selection.data("select2-data");
|
data = this.selection.data("select2-data");
|
||||||
|
if (data == undefined) data = null;
|
||||||
|
return data;
|
||||||
} else {
|
} else {
|
||||||
if (!value || value === "") {
|
if (!value || value === "") {
|
||||||
this.clear();
|
this.clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user