JsTree disable some checkboxes

Using jsTree (3.1.0+) with the checkbox plugin allows you to enable not all checkboxes - disable some of them?

I found a solution for older jsTree versions here jstree disable checkbox , but it does not work in jsTree 3.1.0+ versions.

Check the "Hide checkbox" box of jsTree Hide Checkbox , but if I click on the folder, the hidden checkbox will be checked anyway.

Thanks.

+4
source share
2 answers

Keep in mind, if you use checkbox.tie_selection as false , the selection and validation are the same thing.

That way you can just call .disable_node() on the nodes you want to disable.


EDIT : use the last code from the repo (note - not 3.1.1, but the last code): https://github.com/vakata/jstree/archive/master.zip

Now you can indicate the status of checkbox_disabled :

 <div id="jstree"> <ul> <li data-jstree='{"checked":true}'>checked</li> <li data-jstree='{"checkbox_disabled":true}'>checked</li> </ul> </div> 

In JSON too, of course:

 { "id" : "Test node", "state" : { "checkbox_disabled" : true } } 

You can also change the disabled state of the checkbox at run time with enable_checkbox(node) and disable_checkbox(node) .

+11
source

To completely hide the checkbox from a specific node, add the following JS code

 $('#tree_2').on('ready.jstree', function () { $("#tree_2").jstree().get_node("node1_id").a_attr["class"] = "no_checkbox"; $("#tree_2").jstree().get_node("node2_id").a_attr["class"] = "no_checkbox"; .... }); 

and in CSS add the following style

 .no_checkbox > i.jstree-checkbox { display: none; } 

It will completely hide the checkbox from the provided node id, it worked like a charm for me. Thanks to this link .

0
source

All Articles