vakata/jstree — Issue #167: Nested checkboxes with override_ui unselectable
Author: lukemarsden
Created: 2012-02-07 12:29:15+00:00
State: open

With nested checkboxes and the override_ui option, I found that clicking on any leaf node checkbox or checkbox name resulted in two click.jstree events firing, thereby selecting and immediately deselecting the intended checkbox. The following patch is a workaround which means that these checkboxes are clickable again. Hope this helps.

```
diff --git a/js/jquery.jstree.js b/js/jquery.jstree.js
index adda18c..3de9ef6 100644
--- a/js/jquery.jstree.js
+++ b/js/jquery.jstree.js
@@ -2754,6 +2754,7 @@
this.select_node = this.deselect_node = this.deselect_all = $.noop;
this.get_selected = this.get_checked;
}
+ this.debounce = false;

this.get_container()
.bind("open_node.jstree create_node.jstree clean_node.jstree refresh.jstree", $.proxy(function (e, data) {
@@ -2763,6 +2764,16 @@
this._prepare_checkboxes();
}, this))
.delegate( (this.data.ui && this.data.checkbox.noui ? "a" : "ins.jstree-checkbox") , "click.jstree", $.proxy(function (e) {
+ // Prevent double click with debounce timer hack.
+ if(this.debounce) {
+ this.debounce = false;
+ e.stopImmediatePropagation();
+ return false;
+ }
+ this.debounce = true;
+ // Save the scope so the setTimeout call can see it.
+ var _this = this; window.setTimeout(function() { _this.debounce = false; }, 0);
e.preventDefault();
if(this._get_node(e.target).hasClass("jstree-checked")) { this.uncheck_node(e.target); }
else { this.check_node(e.target); }
```