I was wondering if there is a function to find a field by name in a PDF.
I already saw a lot of examples using Resolvenode, however, these examples always used the path to the node (page.subform.etc). Because I don´t know where the field will be or even if the fields really exists, I would like to search for it easily. The only solution I had found was to interact through all the nodes on each page, but this seems not very efficient.
Say for example the field is called MyTestField, you can use resolveNode() to search for it like so:
This is much less efficient than drilling down a bit and looking in a specific section, but if you have no idea where the node could be then you don't have much choice. This will start from the top and search the DOM node by node until it finds MyTestField.
I have a question to go along with this. I'm still not clear on how to get to a certain field in one of the instances of a subform. For example
There are four instances of a subform called mySubForm. In each of the subforms there are three fields: Field1, Field2, Field3. How do I get or set the value for "Field2" in the second instance of the subform?
The occurances of the subform is defined in the Repeat Subform for each Data Item > Initial Count = 4.
I couldn't understand why it wasn't working when I put in the instance number (mySubForm). It seemed logical to me. It looks like I have to isolate the instance inside the parenthesis first then access the field outside the parenthesis.
Ok, apparently resolveNode() works a little different from what I thought, and I just learned something new, so thanks :d
The way resolveNode() works is it will start from the node that it is called from. So xfa.resolveNode() starts from top level. Whereas, xfa.form.formName.subForm1.subForm2.resolveNode() would start from the subForm2. At this point it will look at all nodes that share the same parent as the one from which it is called from. If it doesn't find what it's looking for it will then traverse UP the tree to look for it (yes, UP, not down). That's why it doesn't find your TextField1, because it is lower in the tree than the top level...
So at this point you may react as I did and say something like "Wow, searching UP a tree is $@#%$# useless". Well, it might actually be useful in some circumstances, and luckily there is a notation you can use to make it search down the tree too. If you do something like:
This tells it to start at form1 (you'd rename this to whatever you top level form node is called) and the .. says look DOWN and find TextField1. So if you use that on your form you will be able to find TextField1 regardless of where it is on the form.
So I can get the user to key in a number in the response dialog that come up specifying which subform use. But how do I combine a response with part of the field name as in Field 1, 2, or 3. So if the user keys in 3 then 3 is put together with Field to get Field3?
Just remember, resolveNode searches through nodes in the DOM looking for the one you want. It's not great for performance. So only use it when you need to, and whenever possible use it such that it will start looking in a position where it will find the node you want as soon as possible.
Thanks for all the help on increasing my understanding. You folks at Adobe are great job.