Skip to content

Commit 8e9e65f

Browse files
committed
Error when clearing a single-select box multiple times. fix select2#908
1 parent 26c3307 commit 8e9e65f

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

select2.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,13 +1749,15 @@ the specific language governing permissions and limitations under the Apache Lic
17491749
// single
17501750
clear: function() {
17511751
var data=this.selection.data("select2-data");
1752-
this.opts.element.val("");
1753-
this.selection.find("span").empty();
1754-
this.selection.removeData("select2-data");
1755-
this.setPlaceholder();
1752+
if (data) { // guard against queued quick consecutive clicks
1753+
this.opts.element.val("");
1754+
this.selection.find("span").empty();
1755+
this.selection.removeData("select2-data");
1756+
this.setPlaceholder();
17561757

1757-
this.opts.element.trigger({ type: "removed", val: this.id(data), choice: data });
1758-
this.triggerChange({removed:data});
1758+
this.opts.element.trigger({ type: "removed", val: this.id(data), choice: data });
1759+
this.triggerChange({removed:data});
1760+
}
17591761
},
17601762

17611763
/**

0 commit comments

Comments
 (0)