Expand my Community achievements bar.

SOLVED

hide parent subforms based on checked value

Avatar

Level 2

Hello,

I have a basic flowed structure that has a number if checkboxes each contained within a parent subform. My goal is to have a button at the end to check for all unchecked values and hide their parent subform. Sadly, I am unable to get it to work and I would really like some help with this. 

 2022-08-08 1-49-32 PM.png

1 Accepted Solution

Avatar

Correct answer by
Level 5

I think I see what you were trying to do, try something like this

checkAllNodes(Page1);
 
function checkAllNodes(pNode){

	var oNodes = pNode.nodes; 
	var nodesLength = oNodes.length; 

	for (var i = 0; i < nodesLength; i++) { 
    	//xfa.host.messageBox(oNodes.item(i).className)
    	if (oNodes.item(i).className === "subform") {
    		checkAllNodes(oNodes.item(i));
    	}
    	if (oNodes.item(i).name === "chkCheckbox") {
			if (oNodes.item(i).rawValue === 0) {
				oNodes.item(i).parent.presence = "hidden";
			}    		
    	}    	    	
    }
	
}

Probably best to put those Subforms (OptionA, OptionB, etc) under their own Subform and start recursion from it rather than Page1.

View solution in original post

4 Replies

Avatar

Employee Advisor

@wilsonl28824783 

You can directly check for the raw value of the field and apply the presence based on the same.

 

var checkboxes = xfa.resolveNodes("chkCheckBox");
    if(checkbox.rawValue == "0")
    {
        [parent subform].presence = "hidden"; 
    }
    break;

Avatar

Level 5

If the subforms are static then you could do the following:

if (Page1.OptionA.chkCheckbox.rawValue === 0) {
	Page1.OptionA.chkCheckbox.parent.presence = "hidden";
}
if (Page1.OptionB.chkCheckbox.rawValue === 0) {
	Page1.OptionB.chkCheckbox.parent.presence = "hidden";
}

Avatar

Correct answer by
Level 5

I think I see what you were trying to do, try something like this

checkAllNodes(Page1);
 
function checkAllNodes(pNode){

	var oNodes = pNode.nodes; 
	var nodesLength = oNodes.length; 

	for (var i = 0; i < nodesLength; i++) { 
    	//xfa.host.messageBox(oNodes.item(i).className)
    	if (oNodes.item(i).className === "subform") {
    		checkAllNodes(oNodes.item(i));
    	}
    	if (oNodes.item(i).name === "chkCheckbox") {
			if (oNodes.item(i).rawValue === 0) {
				oNodes.item(i).parent.presence = "hidden";
			}    		
    	}    	    	
    }
	
}

Probably best to put those Subforms (OptionA, OptionB, etc) under their own Subform and start recursion from it rather than Page1.

Avatar

Community Advisor

This script will work with any name for the checkbox

 

checkAllNodes(Page1);

function checkAllNodes(pNode){

var oNodes = pNode.nodes;
var nodesLength = oNodes.length;

for (var i = 0; i < nodesLength; i++) {
if (oNodes.item(i).className === "subform") {
checkAllNodes(oNodes.item(i));
}
if (oNodes.item(i).className === "field") {
if (oNodes.item(i).ui.oneOfChild.className == "checkButton") {
if (oNodes.item(i).rawValue === 0) {
oNodes.item(i).parent.presence = "hidden";
}
}
}
}

}