Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Issue with jQuery in tree with checkboxes

Apex-UserAug 25 2015 — edited Sep 1 2015

Hi all,

I'm using the jQuery code detailed here to add checkboxes to my apex tree region.

regTree = apex.jQuery("#viewtree").find("div.tree");

regTree.tree({

ui : {

  theme_name : "checkbox"

},

callback : {

  onchange : function(NODE, TREE_OBJ) {

   if (TREE_OBJ.settings.ui.theme_name == "checkbox") {

    var $this = $(NODE).is("li") ? $(NODE) : $(NODE).parent();

    if ($this.children("a.unchecked").size() == 0) {

     TREE_OBJ.container.find("a").addClass("unchecked");

    }

    $this.children("a").removeClass("clicked");

    if ($this.children("a").hasClass("checked")) {

     $this.find("li").andSelf().children("a").removeClass("checked").removeClass("undetermined").addClass("unchecked");

     var state = 0;

    } else {

     $this.find("li").andSelf().children("a").removeClass("unchecked").removeClass("undetermined").addClass("checked");

     var state = 1;

    }

                $this.parents("li").each(function() {

     if (state == 1) {

      if ($(this).find("a.unchecked, a.undetermined").size() - 1 > 0) {

       $(this).parents("li").andSelf().children("a").removeClass("unchecked").removeClass("checked").addClass("undetermined");

       return false;

      } else

       $(this).children("a").removeClass("unchecked").removeClass("undetermined").addClass("checked");

     } else {

      if ($(this).find("a.checked, a.undetermined").size() - 1 > 0) {

       $(this).parents("li").andSelf().children("a").removeClass("unchecked").removeClass("checked").addClass("undetermined");

       return false;

      } else

       $(this).children("a").removeClass("checked").removeClass("undetermined").addClass("unchecked");

     }

    });

   }

  }

       ,onopen : function(NODE, TREE_OBJ) {

           $(NODE).removeClass("open").addClass("closed");

        }

       ,onclose : function(NODE, TREE_OBJ) {

           $(NODE).removeClass("closed").addClass("open");

        }

}

});

But I'm having some issues with the jQuery, where opening and closing the last siblings of a branch doesn't correctly apply the checked/undetermined class to the parent node..

Is anyone able to assist to fix up the jQuery? I'm not confident in jQuery to fix it properly, though I think it may relate to this bit of code:

if ($this.children("a.unchecked").size() == 0) {

     TREE_OBJ.container.find("a").addClass("unchecked");

    }

A working example is here.  If you open department one, then select all the teams, then deselect/select them a couple of times you'll see the state of the parent node gets confused.

Apex is version 4.2.3

Many thanks!

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 29 2015
Added on Aug 25 2015
6 comments
1,648 views