Could someone direct me to a good explanation of when/how to use oSubform in JavaScript? Purpose? Best practices?
Thanks! ~Carol
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
Yes that is the general idea.
The variable will exist within the event that it is scripted for. So if the script to subformPageTwo is in a different event, then you can reuse oSubform.
However if you are referencing the two subforms in one block of script, it might be better to declare two variables:
var oSubform1 = subformPageOne;
var oSubform2 = subformPageTwo;
Or you can use oSubform for both subforms, but re-declaring the variable when you are finished with subformPageOne:
var oSubform = subformPageOne;
... //using the variable multiple times
var oSubform = subformPageTwo; // finished with subformPageOne
... //using the variable multiple times
It really is up to you as to what you are trying to achieve in the script. Hope that helps,
Niall
Views
Replies
Total Likes
Hi Carol,
Not sure if I am picking up your question right...
oSubform looks like a variable referencing an actual subform in a form. In this case you might assign a subform to a variable, if you are going to reference that subform a lot of times in an event's script.
var oSubform = form1.page1.mySubform;
oSubform.presence = "invisible";
...
This would also be very useful if you had to resolveNode the subform, because you would do this once when declaring the variable, instead of doing it multiple times.
I am not completely sure of best practice, but when declaring a variable some people put a letter in front of the variable name to indicate the variable type. This is approximate:
n = number
o = object
v = variable
s = string
Hope that helps,
Niall
Views
Replies
Total Likes
This is making sense.
So, let's say I have set my variable as:
var oSubform = xfa.resolveNode("AgencySurveyForm.subformPageOne")
and the following code references it as follows:
var strAgencyName = oSubform.AgencyName.rawValue;
if(strAgencyName == null || strAgencyName == ""){
isMandatoryFieldMissed.value = "1";
strFirstMissedField = oSubform.resolveNode("AgencyName");
}
After I have finished referencing that particular subform multiple times in my script, how do I change to another subform (e.g., subformPageTwo)? Do I just create a new var oSubform, or does PageOne somehow need to be released before PageTwo is declared?
Views
Replies
Total Likes
Hi,
Yes that is the general idea.
The variable will exist within the event that it is scripted for. So if the script to subformPageTwo is in a different event, then you can reuse oSubform.
However if you are referencing the two subforms in one block of script, it might be better to declare two variables:
var oSubform1 = subformPageOne;
var oSubform2 = subformPageTwo;
Or you can use oSubform for both subforms, but re-declaring the variable when you are finished with subformPageOne:
var oSubform = subformPageOne;
... //using the variable multiple times
var oSubform = subformPageTwo; // finished with subformPageOne
... //using the variable multiple times
It really is up to you as to what you are trying to achieve in the script. Hope that helps,
Niall
Views
Replies
Total Likes
That is exactly what I am looking for. Thank you for helping me to understand, Niall, and thanks for your time! ~Carol
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies