Is there a possibility to use the same script in different fields?
I got several scripts that will validate and change the user entries on different fields. Since they all do exactly the same thing, isn't it possible to just take the "real" script out on one field and refer on other fields to this script?
Solved! Go to Solution.
Views
Replies
Total Likes
Sure - we have a "commonScriptObjects.xdp" fragment that we keep all of
our common javascript methods in. Then we add it to the form and hide it,
then use the following reference to point to the script object:
//GET A HANDLE TO THE SCRIPT OBJECT
var commonScript =
xfa.resolveNode("commonScriptObjectsFrag.fragmentScript");
//CALL A JAVASCRIPT METHOD IN THE SCRIPT OBJECT
commonScript.setupSearch();
Here's another thing we do to validate our required fields. We pass in
the actual field to validate and the name of the field as a text string:
if (!commonScript.validateRequired(mainContentSubform.customerName,
"Customer")) return false;
and the method to validateRequired, which is in our commonScriptObject xdp
file, looks like this:
// validate required fields
function validateRequired(oField, fieldName) {
console.println("enter validateRequired");
var commonScript =
xfa.resolveNode("commonScriptObjectsFrag.fragmentScript");
if (commonScript.isNullValue(oField.rawValue))
{
xfa.host.messageBox("Please complete the '" + fieldName +
"' field.", "Error Message", 3);
xfa.host.setFocus(oField);
return false;
}
return true;
}
Hope that helps,
Elaine
ocen12 <forums@adobe.com>
07/29/2009 09:26 AM
Please respond to
clearspace-510205244-333209-2-2140242@mail.forums.adobe.com
To
Amal Schmitz <akschmitz@comerica.com>
cc
Subject
Use same script in different fields?
Is there a possibility to use the same script in different fields?
I got several scripts that will validate and change the user entries on
different fields. Since they all do exactly the same thing, isn't it
possible to just take the "real" script out on one field and refer on
other fields to this script?
Views
Replies
Total Likes
Sure - we have a "commonScriptObjects.xdp" fragment that we keep all of
our common javascript methods in. Then we add it to the form and hide it,
then use the following reference to point to the script object:
//GET A HANDLE TO THE SCRIPT OBJECT
var commonScript =
xfa.resolveNode("commonScriptObjectsFrag.fragmentScript");
//CALL A JAVASCRIPT METHOD IN THE SCRIPT OBJECT
commonScript.setupSearch();
Here's another thing we do to validate our required fields. We pass in
the actual field to validate and the name of the field as a text string:
if (!commonScript.validateRequired(mainContentSubform.customerName,
"Customer")) return false;
and the method to validateRequired, which is in our commonScriptObject xdp
file, looks like this:
// validate required fields
function validateRequired(oField, fieldName) {
console.println("enter validateRequired");
var commonScript =
xfa.resolveNode("commonScriptObjectsFrag.fragmentScript");
if (commonScript.isNullValue(oField.rawValue))
{
xfa.host.messageBox("Please complete the '" + fieldName +
"' field.", "Error Message", 3);
xfa.host.setFocus(oField);
return false;
}
return true;
}
Hope that helps,
Elaine
ocen12 <forums@adobe.com>
07/29/2009 09:26 AM
Please respond to
clearspace-510205244-333209-2-2140242@mail.forums.adobe.com
To
Amal Schmitz <akschmitz@comerica.com>
cc
Subject
Use same script in different fields?
Is there a possibility to use the same script in different fields?
I got several scripts that will validate and change the user entries on
different fields. Since they all do exactly the same thing, isn't it
possible to just take the "real" script out on one field and refer on
other fields to this script?
Views
Replies
Total Likes
Thanx
I'll have a closer look to this one in some time, since right now I don't have much time (and I never worked with fragments before).
Views
Replies
Total Likes
Why not use the actual Script Objects?
Views
Replies
Total Likes
Jono, not sure I understand. In our fragment, we have a "fragmentScript"
script object that holds all of the common javascript, and we just add
that fragment in the forms that need the common javascript.
Views
Replies
Total Likes
I mean the Script Objects in the Variables section of the Form Hierarchy.
I've got script fragments I'm using too but I just drag them to the Hierarchy palette (I recently found out you could do that) and reference them directly.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies