Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Tibor on Jan 11, 2008 10:12
open dhtmlx forum
What is the recommended way of handling checkbox changes? ...

What is the recommended way of handling checkbox changes?
Answer posted by Support on Jan 11, 2008 10:15
Do you mean tree or grid ?
Both components have inner events, which can be used to add some custom reaction on checkbox state changing, events receive id of element for which checkbox changed and its new value, returning false from event handler will deny checkbox change.

In case of tree
    tree.attachEvent("onCheck",function(id,state){
          //custom code here
          return true;
    });

In case of grid
    grid.attachEvent("onCheckbox",function(id,ind,state){
          //custom code here
          return true;
    });

Answer posted by Tibor on Jan 12, 2008 02:04
It's a tree.
As you stated in your previous answer, the onCheck is actually a wrongly named onCheckboxClick event, and can't be used to handle checkbox changes.
http://dhtmlx.com/docs/products/kb/index.php?s=normal&q=1745&a=2006

So my question is how can I respond to checkbox check state changes?
At the moment there are 3 scenarios I should handle:
-user clicks on a checkbox at upper level in tree.
-setCheck or other method is invoked.
-a new node is added to the tree, with checked checkbox.
Answer posted by Support on Jan 14, 2008 03:33
>>-user clicks on a checkbox at upper level in tree
You will get an event for top level item only

>>-setCheck or other method is invoked.
will not generate any events

>>-a new node is added to the tree, with checked checkbox.
will not generate any events

The only way in your case is to introduce new event , it can be done by adding next line in source code of dhtmlxtree.js
   dhtmlXTreeObject.prototype._setCheck=function(sNode,state){
       ...
       this._setSrc(z,this.imPath+((sNode.parentObject._r_logic||this._frbtr)?this.radioArray:this.checkArray)[sNode.checkstate]);
       this.callEvent("customCheck",[sNode.id,sNode.checkstate]); // << this line need to be added
   };

after such code modification, you will be able to use
    tree.attachEvent("customCheck",function(){ ...
to handle any checkbox state change in tree