Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jstree checkboxes in forms

Sorry for the slightly ambiguous title. My problem is very specific (and it's probably just me being a newb), I just didn't know how to explain it in the title.

I'm currently upgrading a webpage. This webpage has 3 lists with items in them, for example the Devices list has different types of cars. Each item has a checkbox, the user checks the ones he wants to use, and then presses a button. Then he receives a report based on his selections.

<input type="button" class="mapbutton"  onclick="company.view.reports.serialize(this);" 
                style="width:280px;font-size:1em" 
                value="<fmt:message key="owner.text.open_report" />" />

This is the code for the button.

serialize: function(what){
              var m = company.model.report;
              var strDev = 'devices=';
              var devicesCB = $(".devicesCB:checked");
              if (devicesCB.length > 0){
                  for (var i=0;i<devicesCB.length;i++) {
                     strDev += devicesCB[i].value + ',';
                  }
                  strDev = strDev.substring(0, strDev.length - 1);
              }

and this is part of the serialize function that is fired when the user presses the button. The $(".devicesCB:checked") part is jQuery, and returns all the checked checkboxes of the class "devicesCB". This line is also the key to my question.

checkbox : {
        "real_checkboxes" : "true",
        "override_ui" : "true",
        "real_checkboxes_names" : function(n){
            console.log("As");
            return[("area"+n[0].id),n[0].id];
        }
    },

According to the jstree documentation, this should create checkboxes that work in forms. Any ideas how I would go about retrieving this data? I have tried var cb = $(".jstree-checkbox:checked") which didn't really do anything, also I tried working with the tree's selector var areasCB = $("#tree"); but I couldn't figure out what to do with it.

I'm pretty sure this is a fairly simple problem, but I'm still very new to jQuery and javascript in general.

like image 681
T.Kaukoranta Avatar asked Jul 17 '26 03:07

T.Kaukoranta


1 Answers

Here is one way of getting the checked nodes:

$("#my_tree").jstree("get_checked", null, false).each(function() {
    //do something
});
like image 154
Mbrevda Avatar answered Jul 19 '26 16:07

Mbrevda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!