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.
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