Highlighted

Dynamic xfa.form Object Reference

Avatar

Guest

27-08-2008

Hi,



I am trying to create a script function on a form so I can perform the same validation against multiple objects in a form. What I want to to is pass the name of the object into this function and then perform different actions against each object.



I'm happy with creating the function, passing in the values and doing what I need to against the objects but I can't work out what syntax should be there to dynamically reference each object that is passed to the function.



e.g.



var sName = "xfa.form.Form.Form.sYourDetails.sFirstName.vFirstName";

script.fnValidate(sName);

var sName = "xfa.form.Form.Form.sYourDetails.sLastName.vFirstName";

script.fnValidate(sName);



function fnValidate(sName){

sName.presence = "hidden";

sName.rawValue = "XYZ";

xfa.form.Form['" + sName"'].rawValue?

etc...

}



Any help would be greatly appreciated.

Replies

Highlighted

pguerett

02-09-2008

When in doubt about an objects name, I will put a message box out (on the enter event) with this code:



app.alert(this.somExpression)



when executed it will show me the Som Expression to get access to the object. When dealing with fields in repeating subforms it is the subform that holds the fields that has the occurance number in it (not the field). So in your case the object you want is:

Form.sYourDetails[occurance number].sFirstName.vFirstName



Assuming sFirstName and VfirstName are fields.



Hope that helps
Highlighted

Avatar

Guest

03-09-2008

Hi Guys,



Thanks for the responses.



I think the problem I had was that when I did CTRL Click on an object, the script showed xfa.resolvedNode instead of xfa.form.ResolveNode.



This meant I had tended to use either of the below means to reference objects in the majority of my scrips: xfa.form.Form.Form.sYourDetails.sFirstName.vFirstName

Form.Form.sYourDetails.sFirstName.vFirstName



Using these I couldn't reference a specific instance or dynamically reference the objet name because I wasn't using resolveNode(s). I new I needed to us it, but it wasn't evaluating as mentioned above.



1. Why fo I need to reference the form dom in the resolveNode Expression?

2. Why wasn;t designer doing this by default?



Thanks Guys.