These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

recursively loop through all nodes in an entire form

AndrewAlb
Registered: Aug 16 2007
Posts: 97
Answered

Has anyone come across code to recursively loop through all fields in a form?
I would like to set up a script that loops through my entire form (all subforms and pages) and manipulate certain fields that match my criteria - e.g. hide buttons from layout, hide subforms whose names match expressions I define etc.

I can do all the actions but I don't know how to recursively loop down through all the nodes starting at xfa.form - or perhaps xfa.form.myForm?

I did find one example at:
http://blogs.adobe.com/formbuilder/2006/06/process_all_fields.php

but it seemed overly complicated for what I thought should simply be a simple command.

Andrew D. Albrecht, MS
Solutions Developer
ING USFS

My Product Information:
LiveCycle Designer, Windows
AndrewAlb
Registered: Aug 16 2007
Posts: 97
I solved my own problem in case anyone is interested in the answer here it is.
While I never found a function in Acrobat I wrote a simple function that will recursively loop through all the nodes in a form given a starting point you specify in the functions parameter. I would love to get feedback or tweaking of this to make it faster or simpler or just plain better.


FUNCTION:
/********************************************************/
//I have put the func in a script variable call 'func'

function allfields(start)
{
var A = start
for (var C = 0; C < A.length; C++)
{

//Here put your action that you want to perform on that object (most likely only
// if it matches certain criteria because remember this will loop through
// EVERYTHING. so you want to specify what you want to act on. e.g.

if (A.item(C).className == "field")
{do something};

//Here the function enters the recursion for that particular object.
if (A.item(C).nodes.length > 0)
{func.allfields(A.item(C).nodes)};
};
};

/********************************************************/FUNCTION CALL:
//Put this in your form somewhere.
//remember you need to call the variable name then the function name.

func.allfields(xfa.form.formName.nodes);

//you can specify any entry point that you want it can be the whole form
//like I do here or a smaller piece like a single subform.


/********************************************************/

Andrew D. Albrecht, MS
Solutions Developer
ING USFS