Skip to content

Commit cb7b546

Browse files
committed
only validate initSelection is present on val() if we are not clearing
1 parent 9a3666e commit cb7b546

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

select2.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ the specific language governing permissions and limitations under the Apache Lic
16361636
this.opts.placeholder ||
16371637
((placeholderOption = this.getPlaceholderOption()) !== undefined && placeholderOption.text());
16381638
},
1639-
1639+
16401640
// abstract
16411641
getPlaceholderOption: function() {
16421642
if (this.select) {
@@ -1992,7 +1992,7 @@ the specific language governing permissions and limitations under the Apache Lic
19921992
});
19931993
}
19941994
},
1995-
1995+
19961996
isPlaceholderOptionSelected: function() {
19971997
var placeholderOption;
19981998
return ((placeholderOption = this.getPlaceholderOption()) !== undefined && placeholderOption.is(':selected')) ||
@@ -2182,14 +2182,14 @@ the specific language governing permissions and limitations under the Apache Lic
21822182
this.triggerChange({added: data, removed:oldData});
21832183
}
21842184
} else {
2185-
if (this.opts.initSelection === undefined) {
2186-
throw new Error("cannot call val() if initSelection() is not defined");
2187-
}
21882185
// val is an id. !val is true for [undefined,null,'',0] - 0 is legal
21892186
if (!val && val !== 0) {
21902187
this.clear(triggerChange);
21912188
return;
21922189
}
2190+
if (this.opts.initSelection === undefined) {
2191+
throw new Error("cannot call val() if initSelection() is not defined");
2192+
}
21932193
this.opts.element.val(val);
21942194
this.opts.initSelection(this.opts.element, function(data){
21952195
self.opts.element.val(!data ? "" : self.id(data));

0 commit comments

Comments
 (0)