Jstree select_limit not working. I want to set a selection restriction to select only 3 nodes

My jstree function is here. I set 'select_limit' : 3 but it does not work. when I start, I can select more than three nodes, but I need to select no more than three nodes.

  j1("#utree_activity").jstree({ "plugins": ["themes", "html_data", "ui", "crrm", "checkbox"], "html_data": { "ajax": { "url": urlGlobal + "jstrees/activitytree/", "asynchronous": "false", "data": function (n) { return { id: n.attr ? n.attr("id") : 0, default_activities: default_activities }; }, "success": function (gb) { }, } }, "ui": { "select_limit": 3, }, "cookies": { cookie_options: { path: "/" } }, "checkbox": { two_state: true, real_checkboxes: false } }); 
+7
source share
2 answers

select_limit doens't handle checkbox you must roll your own before.jstree method.

 j1.bind("before.jstree", function (e, data) { if (data.func === "check_node") { if (j1.jstree('get_checked').length >= 1) { e.preventDefault(); return false; } } }); 

Please note that this code, if only for example, does not process child nodes

Working fiddle: http://jsfiddle.net/cfb9J/1/

+8
source

There is one more option left, you may need to add the ui module, try the following:

 j1("#utree_activity").jstree({ "plugins" : ["html_data","ui"], //the rest of your code }); 
0
source

All Articles