Skip to content
Advertisement

jstree select_limit not working. I want to set selection limit to select only 3 nodes

My jstree function is here.
I have set 'select_limit' : 3, but is not working. when I run, I am able to select more than 3 nodes, but I need to select no more than 3 nodes.

     var j1 = jQuery.noConflict();
     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
        }
    });

Advertisement

Answer

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;                
        }
    }
});

Note that this code if for example only, and doesn’t handle child nodes

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

Advertisement