only validate initSelection is present on val() if we are not clearing
This commit is contained in:
parent
9a3666edb5
commit
cb7b5464a1
10
select2.js
10
select2.js
@ -1636,7 +1636,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
this.opts.placeholder ||
|
this.opts.placeholder ||
|
||||||
((placeholderOption = this.getPlaceholderOption()) !== undefined && placeholderOption.text());
|
((placeholderOption = this.getPlaceholderOption()) !== undefined && placeholderOption.text());
|
||||||
},
|
},
|
||||||
|
|
||||||
// abstract
|
// abstract
|
||||||
getPlaceholderOption: function() {
|
getPlaceholderOption: function() {
|
||||||
if (this.select) {
|
if (this.select) {
|
||||||
@ -1992,7 +1992,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
isPlaceholderOptionSelected: function() {
|
isPlaceholderOptionSelected: function() {
|
||||||
var placeholderOption;
|
var placeholderOption;
|
||||||
return ((placeholderOption = this.getPlaceholderOption()) !== undefined && placeholderOption.is(':selected')) ||
|
return ((placeholderOption = this.getPlaceholderOption()) !== undefined && placeholderOption.is(':selected')) ||
|
||||||
@ -2182,14 +2182,14 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
this.triggerChange({added: data, removed:oldData});
|
this.triggerChange({added: data, removed:oldData});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.opts.initSelection === undefined) {
|
|
||||||
throw new Error("cannot call val() if initSelection() is not defined");
|
|
||||||
}
|
|
||||||
// val is an id. !val is true for [undefined,null,'',0] - 0 is legal
|
// val is an id. !val is true for [undefined,null,'',0] - 0 is legal
|
||||||
if (!val && val !== 0) {
|
if (!val && val !== 0) {
|
||||||
this.clear(triggerChange);
|
this.clear(triggerChange);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (this.opts.initSelection === undefined) {
|
||||||
|
throw new Error("cannot call val() if initSelection() is not defined");
|
||||||
|
}
|
||||||
this.opts.element.val(val);
|
this.opts.element.val(val);
|
||||||
this.opts.initSelection(this.opts.element, function(data){
|
this.opts.initSelection(this.opts.element, function(data){
|
||||||
self.opts.element.val(!data ? "" : self.id(data));
|
self.opts.element.val(!data ? "" : self.id(data));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user