Multiple repeating SubForms binding to the same data node | Community
Skip to main content
February 28, 2013
Question

Multiple repeating SubForms binding to the same data node

  • February 28, 2013
  • 14 replies
  • 14251 views

Having multiple repeating SubForms binding to the same data node : In our documents, many times we need to display information from same table in multiple locations. For example, if document displays information of Insureds on one page and information of drivers on another page, we need to create a LiveCycle document with two SubForms. Each SubForm needs to have a repeating binding to CommonInsured element in XSD.  LiveCycle Designer is not able to handle such case. We cannot have two subforms bound to the same node, ONLY in a case where repeating option is selected for data binding.

The only way I have found out is the following Javascript

//Get the data node from XML. You will find the code for this function in //JavaHelperFunctions library.

// InsuredDataRepeatingSubForm is a second subform.

//You need to manually add instances to this subform at the

//runtime and Insured data to each instance.

var insuArray = JavaHelperFunctions.getInsureds();

    var i=0;

    for( i=0; i<insuArray.length; i++)

    {

       if (i>0)

       {

var thesubform = this.InsuredDataRepeatingSubForm.instanceManager.addInstance(i);

              thesubform.InsuredName.rawValue = insuArray[i].fullName.value;

       }  

       else

       {

               this.InsuredDataRepeatingSubForm.InsuredName.rawValue = insuArray[i].fullName.value;

       }

    }

Is there any way I can achieve directly using bindings since we are trying to minimize javascript that changes the layout of the form?

Thanks in advance!

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

14 replies

New Participant
March 8, 2013

Kyle,

I wanted to use your code but as I am new to coding I have to ask a very basic question.

I have a repeating table subform which I want to duplicate on a second page.  i.e., I want row1 in the target table subform to be the same as row1 in the source table subform.

Where in the script do I identify the source and target subforms/tables.... 

Would I stop at the Row1 itentifier? i.e.,

var sourceSubform=source.resolveNode(topmostSubform.Page1.WitnessNameSubform.Table3.Row1.name.substr(1)).all.item(a);

I would appreciate any help.  Thank you in advance.  Vanessa

March 1, 2013

Thanks for the reply. Atleast gives me re-affirmation that i'm doing the right thing and there is no way to achieve this directly using bindings.

New Participant
March 1, 2013

Unfortunately not. I've spent countless hours/days trying to do the same thing. You have to use code. The form consumes all the data it can into the repeating elements until there is none left and it is not reused.

Here's a function I wrote just for that purpose. Feel free to use it:

function loadData(source,target){

target.setInstances(source.count);//set the target's subform instances to match the source's

for (var a=0;a<source.count;a++){//loop through each subform instance

  var sourceSubform=source.resolveNode(source.name.substr(1)).all.item(a);

  var targetSubform=target.resolveNode(target.name.substr(1)).all.item(a);

  for (var b=0;b<sourceSubform.nodes.length;b++){//loop through the children of each

   if (sourceSubform.nodes.item(b).className=="field" && targetSubform.resolveNode(sourceSubform.nodes.item(b).name)!=null)//check for matching fields

    if (typeof(targetSubform.resolveNode(sourceSubform.nodes.item(b).name).value.exData)=="undefined" ||

     typeof(targetSubform.resolveNode(sourceSubform.nodes.item(b).name).value.exData.body)=="undefined")

     targetSubform.resolveNode(sourceSubform.nodes.item(b).name).rawValue=sourceSubform.nodes.item(b).rawValue;

    else

     targetSubform.resolveNode(sourceSubform.nodes.item(b).name).value.exData.loadXML(sourceSubform.nodes.item(b).value.exData.saveXML(),1,1);

   if (sourceSubform.nodes.item(b).className=="instanceManager" && targetSubform.resolveNode(sourceSubform.nodes.item(b).name)!=null)//check for matching subforms

    loadData(sourceSubform.nodes.item(b),targetSubform.resolveNode(sourceSubform.nodes.item(b).name));

  }

}

}

Just make sure the source and target subform hierarchies are identifal, same name and all. It will recurse down the tree and transfer source fields (rich text and plain) to their sister targets.

Kyle

February 28, 2013

"Is there any way I can achieve directly using bindings since we are trying to minimize javascript that changes the layout of the form?"

Yes. Have you created a Schema, data connection to it and bound your form elements? If you bind two elements to the same item in the data connection, when you change one, the other changes.