admin管理员组文章数量:1178571
I've tried to capture select2:clearing
event
$("#my-select").on("select2:clearing", function (e) {
console.log('cleared');
});
(jsfiddle)
but it is not fired. I've also tried other versions (like select2:removed
etc., see another question with similar problem), but it also doesn't work.
I use select2 4.0.0-beta2.
I've tried to capture select2:clearing
event
$("#my-select").on("select2:clearing", function (e) {
console.log('cleared');
});
(jsfiddle)
but it is not fired. I've also tried other versions (like select2:removed
etc., see another question with similar problem), but it also doesn't work.
I use select2 4.0.0-beta2.
Share Improve this question edited Jan 26, 2020 at 22:41 Brian Tompsett - 汤莱恩 5,87372 gold badges61 silver badges133 bronze badges asked Jan 21, 2015 at 11:00 LA_LA_ 20.4k60 gold badges176 silver badges316 bronze badges 2- Never used this library, but in the docs a dash is used in the event names instead of a colon, e.g. select2-clearing – Mario A Commented Jan 21, 2015 at 11:14
- @MarioA, I've tried dashes, but the current doc (see select2.github.io/examples.html, Events section) says about colon. – LA_ Commented Jan 21, 2015 at 11:20
4 Answers
Reset to default 19This works:
$("#my-select").on("select2:unselecting", function(e) {
});
The changelog of select2 4.0.0-beta2 states:
Removed events
select2-clearing - Use select2:unselecting instead
https://github.com/select2/select2/releases
$("#my-select").on("select2:select select2:unselecting", function(e) {
//do something here
});
According to the select2 event documentations, all of the unselect, unselecting, clear and clearing events will works !
But consider that usnselect or unselecting events should be used by single selection mode, and clear or clearing should be used by multi selection mode. So the clear or clearing will fires if all of selected items cleared or clearing.
The differences between unselect and unselecting, is that unselecting fires before removing selection so you can prevented it.
Hope that it helps.
本文标签: javascriptHow to capture event when allowClear option of select2 is chosenStack Overflow
版权声明:本文标题:javascript - How to capture event when allowClear option of select2 is chosen? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1737989392a2045299.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论