hide parent subforms based on checked value | Community
Skip to main content
Level 2
August 8, 2022
Solved

hide parent subforms based on checked value

  • August 8, 2022
  • 3 replies
  • 1322 views

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. 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by MorisMonk

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.

3 replies

Pulkit_Jain_
Adobe Employee
Adobe Employee
August 9, 2022

@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;
Level 4
August 9, 2022

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";
}
MorisMonkAccepted solution
Level 4
August 9, 2022

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.

Vijay_Katoch
Community Advisor
Community Advisor
August 9, 2022

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";
}
}
}
}

}