Expand my Community achievements bar.

Identify and remove a particular instance

Avatar

Former Community Member

I need some assistance with this. I have a checkbox which creates an instance in a seperate form when checked. It creates, gives values to dropdown lists in that instance, and moves it to the end of all the previous instances just fine.

I cant seem to get the removeal of this field to work when the checkbox is deselected. Since users have the ability to reorder instances I cant just remove the last instance, I need the removal to happen based on the value of the dllField when that value = "Text"

Here is my code:

//CheckBox value
varValue=this.rawValue

//Checkbox = unchecked
if (varValue==0)
{
//remove instance where ddlField = "Text"
var instanceOCRRem = xfa.form.RicohStandardEDDForm.Page6.sub18ExportFieldedDataFields.subconcordancefields.subRows.subRow.resolveNode("subRow").ddlField.rawValue="Text"
xfa.form.RicohStandardEDDForm.Page6.sub18ExportFieldedDataFields.subconcordancefields.subRows.subRow.instanceManager.removeInstance(instanceOCRRem);
}
//Checkbox = Checked
else if (varValue==1)
{
//add instance, set the value of the ddlField and ddlECapField, then move it to the end of all the previous instances
var instanceOCR = xfa.form.RicohStandardEDDForm.Page6.sub18ExportFieldedDataFields.subconcordancefields.subRows.subRow.instanceManager.insertInstance(1,true)
var nIndexFrom = instanceOCR.resolveNode("subRow").index;
var instanceCount = xfa.form.RicohStandardEDDForm.Page6.sub18ExportFieldedDataFields.subconcordancefields.subRows.subRow.instanceManager.count -1;
instanceOCR.ddlField.rawValue="Text"
instanceOCR.ddlECapField.rawValue="OCR Text"
instanceOCR.resolveNode("subRow").instanceManager.moveInstance(nIndexFrom,instanceCount);
};

2 Replies

Avatar

Level 10

You need a loop to go through the instances to find the one you want.

I've uploaded a quick sample here:

https://acrobat.com/#d=HCE5l51RbmjfxSkjGIZbDA

I've just done one subform (subHolder) with a repeating subform inside it (subRepeat). It presents multiples of a repeating subform with the index displayed and a textfield that you can type into, if the value of the textfield is "text" it will remove that subform when you click off the checkbox.

var vInstances = this.resolveNodes("subHolder.subRepeat[*]");

if (this.rawValue == 1){

          subHolder._subRepeat.addInstance(1);

}

else{

          for (i = 0; i < vInstances.length; i++) {

                    if (vInstances.item(i).TextField2.rawValue == "text"){

                              vInstances.item(i).instanceManager.removeInstance(i);

                    }

          }

}

You can shorten your add routine by using addInstance() instead of insertInstance() + moveInstance() - addInstance() puts the object at the end.

The underscore before the repeating object is a shortcut to the instanceManager.

Avatar

Former Community Member

Thank you. It took some finagling, but I got it working. Also used it to enhance some other functions in my form too, so very much appreciated!