Skip to content

Commit 4dc2a62

Browse files
committed
Merge pull request select2#619 from cup-of-giraf/master
Trigger an event on value programatically change
2 parents 739a7bf + 09d2958 commit 4dc2a62

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

select2.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,20 +1739,23 @@ the specific language governing permissions and limitations under the Apache Lic
17391739
});
17401740
this.updateSelection(data);
17411741
this.setPlaceholder();
1742+
this.triggerChange();
17421743
} else {
17431744
if (this.opts.initSelection === undefined) {
17441745
throw new Error("cannot call val() if initSelection() is not defined");
17451746
}
17461747
// val is an id. !val is true for [undefined,null,'']
17471748
if (!val) {
17481749
this.clear();
1750+
this.triggerChange();
17491751
return;
17501752
}
17511753
this.opts.element.val(val);
17521754
this.opts.initSelection(this.opts.element, function(data){
17531755
self.opts.element.val(!data ? "" : self.id(data));
17541756
self.updateSelection(data);
17551757
self.setPlaceholder();
1758+
self.triggerChange();
17561759
});
17571760
}
17581761
},
@@ -2251,6 +2254,7 @@ the specific language governing permissions and limitations under the Apache Lic
22512254
this.opts.element.val("");
22522255
this.updateSelection([]);
22532256
this.clearSearch();
2257+
this.triggerChange();
22542258
return;
22552259
}
22562260

@@ -2262,6 +2266,7 @@ the specific language governing permissions and limitations under the Apache Lic
22622266
data.push({id: $(this).attr("value"), text: $(this).text()});
22632267
});
22642268
this.updateSelection(data);
2269+
this.triggerChange();
22652270
} else {
22662271
if (this.opts.initSelection === undefined) {
22672272
throw new Error("val() cannot be called if initSelection() is not defined")
@@ -2272,6 +2277,7 @@ the specific language governing permissions and limitations under the Apache Lic
22722277
self.setVal(ids);
22732278
self.updateSelection(data);
22742279
self.clearSearch();
2280+
self.triggerChange();
22752281
});
22762282
}
22772283
this.clearSearch();

0 commit comments

Comments
 (0)