Skip to content

Commit 08b75a1

Browse files
author
Vincent Petry
committed
Do not trigger event when calling clear() from val() with empty value
1 parent cd0adbe commit 08b75a1

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

select2.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,16 +1747,18 @@ the specific language governing permissions and limitations under the Apache Lic
17471747
},
17481748

17491749
// single
1750-
clear: function() {
1750+
clear: function(triggerChange) {
17511751
var data=this.selection.data("select2-data");
17521752
if (data) { // guard against queued quick consecutive clicks
17531753
this.opts.element.val("");
17541754
this.selection.find("span").empty();
17551755
this.selection.removeData("select2-data");
17561756
this.setPlaceholder();
17571757

1758-
this.opts.element.trigger({ type: "removed", val: this.id(data), choice: data });
1759-
this.triggerChange({removed:data});
1758+
if (triggerChange !== false){
1759+
this.opts.element.trigger({ type: "removed", val: this.id(data), choice: data });
1760+
this.triggerChange({removed:data});
1761+
}
17601762
}
17611763
},
17621764

@@ -1946,7 +1948,7 @@ the specific language governing permissions and limitations under the Apache Lic
19461948
}
19471949
// val is an id. !val is true for [undefined,null,'',0] - 0 is legal
19481950
if (!val && val !== 0) {
1949-
this.clear();
1951+
this.clear(triggerChange);
19501952
if (triggerChange) {
19511953
this.triggerChange();
19521954
}

0 commit comments

Comments
 (0)