Hi there,
I'm using the flytreeview component. It's a simple tree with checkboxes for all items, the tree has 4 levels. I'm using the javascript functions from the demo page to check (and uncheck) all children when a checkbox is ticked/unticked.
Now the javascript function works fine when all items are expanded at least once. When the tree is not expanded yet and you check a top level item, then a javascript error appears. It looks like the checkboxes are not created yet but the system tries to check the box anyway. Underneath is the javascript code I used.
var ignoreEvents = false;
function handleNodeEvent2(){
if (ignoreEvents) return;
ignoreEvents = true;
var node = window.event.node;
if (window.event.eventName == "ONLOADCHILDRENFINISHED") {
setChildrenCheckBox(node, node.IsChecked);
}
else if (window.event.eventName == "ONCHECKED") {
setChildrenCheckBox(node, true);
if (allSiblingChecked(node)) {
setParentCheckBox(node, true);
}
}
else if (window.event.eventName == "ONUNCHECKED") {
setChildrenCheckBox(node, false);
setParentCheckBox(node, false);
}
ignoreEvents = false;
}
function allSiblingChecked(node){
var nodes = node.ParentNode == null ? node.TreeView.Nodes : node.ParentNode.Nodes;
var allChecked = true;
for(var i = 0; i < nodes.length; i++) {
if (!nodes[i].IsChecked){
allChecked = false;
}
}
return allChecked;
}
function setParentCheckBox(node, value){
var parentNode = node.ParentNode;
if (parentNode == null) return;
if (parentNode.IsChecked != value)
parentNode.CheckBoxChange();
if (!value || allSiblingChecked(parentNode))
setParentCheckBox(parentNode, value);
}
function setChildrenCheckBox(parentNode, value){
for(var i = 0; i < parentNode.Nodes.length; i++) {
var node = parentNode.Nodes[i];
if (node.IsChecked != value)
node.CheckBoxChange();
setChildrenCheckBox(node, value);
}
}
The error seams to appear on the line: node.CheckBoxChange();
I hope someone can help as it is a pain.
Best regards Patrick