Dynamic xfa.form Object Reference

Avatar

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

Avatar

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile
pguerett
Level 10

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

Avatar

Avatar
Validate 1
Level 3
xrum
Level 3

Likes

7 likes

Total Posts

89 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Applaud 5
View profile

Avatar
Validate 1
Level 3
xrum
Level 3

Likes

7 likes

Total Posts

89 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Applaud 5
View profile
xrum
Level 3

03-09-2008

try using Nodes, then you can go down a subform, and reference "everything" in it.

Avatar

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.