Repeating subform within another subform javascript issue | Community
Skip to main content
Level 2
March 14, 2024
Solved

Repeating subform within another subform javascript issue

  • March 14, 2024
  • 2 replies
  • 1521 views

Hi, I am building a dynamic form.  Each section is wrapped in in a subform.  two sections have subforms within a parent subform. ex. form1.headersubform.childsubform.child2subform.  I have a button that on the click event uses javascript code to check for empty/null field and colors the fields yellow and sets another var which prevents signature. Everything works, except for the 2 and greater instances of child2subform.  The fields in header subform color fine for every repeating instance.  The child2subform within the headersubform only colors for the 1st instance.   

I can't find the issue in the code to get the child2subform instance to color.  

 

My Javascript

var DDSC = form1.headersubform.childsubform.child2subform.instanceManager.count;

for (var sprec = 0; sprec < DDSC; sprec++) {
for (i = 0; i < DDS.length; i++) {

// check for null or empty value
if (isEmptyField("headersubform.childsubform.child2subformd[" + sprec + "]." + DDS[i])) {
// change the field to required
this.resolveNode("fheadersubform.childsubform.child2subform[" + sprec +"]." + DDS[i]).ui.oneOfChild.border.fill.color.value = "255, 255, 153";
missingData = true;
} else {
// change the field to normal
this.resolveNode("fheadersubform.childsubform.child2subform[" + sprec +"]." + DDS[i]).ui.oneOfChild.border.fill.color.value = "255, 255, 255";
}
}
}

 

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 Vijay_Katoch

Thank you for the assistance - can you return the updated form for reference.  Thank you again! 


Here is the code to check for empty field and revert the color of field to normal if not null.

 

var oNodes = xfa.resolveNodes("DesignDesignation.Designation[*]"); 
var nNodesLength = oNodes.length; 
 
for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) { 
    var cItem = oNodes.item(nNodeCount);
    if(cItem.DesignDesignationSR.rawValue == null){
    cItem.DesignDesignationSR.ui.oneOfChild.border.fill.color.value = "255, 255, 153";
    }else{
    cItem.DesignDesignationSR.ui.oneOfChild.border.fill.color.value = "255, 255, 255";
    }
    var dNodes = cItem.resolveNodes("DesignSpeed.DesignSpd[*]");
    var dNodesLength = dNodes.length;
    for (var dNodeCount = 0; dNodeCount < dNodesLength; dNodeCount++) { 
    var dItem = dNodes.item(dNodeCount);
    if(dItem.DesSpeed.rawValue == null){
    dItem.DesSpeed.ui.oneOfChild.border.fill.color.value = "255, 255, 153";
    } else{
    dItem.DesSpeed.ui.oneOfChild.border.fill.color.value = "255, 255, 255";
    }
}   
}

 

2 replies

Vijay_Katoch
Community Advisor
Community Advisor
March 19, 2024

For DDS[i], use it like the same you are using [" + sprec + "].".

It should work then.

TGD3Author
Level 2
March 19, 2024

Tried that, now no instances color when null.  I am very new to javascript.

I tried 

this.resolveNode("headersubform.childsubform.child2subform[" + sprec +"]." + DDS[" + sprec + "]).ui.oneOfChild.border.fill.color.value = "255, 255, 153";

 

Is that what you meant? 

Vijay_Katoch
Community Advisor
Community Advisor
March 19, 2024

this.resolveNode("headersubform.childsubform.child2subform[" + sprec +"]." + "DDS[" + i + "]").ui.oneOfChild.border.fill.color.value = "255, 255, 153";

kautuk_sahni
Community Manager
Community Manager
March 20, 2024

@tgd3 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni