Expand my Community achievements bar.

Applications for the 2024-2025 Adobe Experience Manager Champion Program are open!
SOLVED

Repeating subform within another subform javascript issue

Avatar

Level 2

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

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

 

View solution in original post

12 Replies

Avatar

Community Advisor

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

It should work then.

Avatar

Level 2

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? 

Avatar

Community Advisor

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

Avatar

Level 2

Result is the same - no instances of the child2subform color 

Avatar

Community Advisor

Share your form, need to look into the form layout and script

Avatar

Level 2

I'd rather email as its a sensitive form than attach it here

Avatar

Community Advisor

I have taken a button in your form and added below script in the click event:

 

This is the code to change the color of fields in parent and child subform. I have added for one field in parent form, you can add for other like I did for "DesignDesignationSR". You can also write your rest of logic.  This will the base code to traverse your parent and child subform fields.

 

var oNodes = xfa.resolveNodes("DesignDesignation.Designation[*]");
var nNodesLength = oNodes.length;

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

 

designDesig.JPG

Avatar

Level 2

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

Avatar

Correct answer by
Community Advisor

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

 

Avatar

Administrator

@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