We have a requirement to include a 'Check form' button on all our forms. This goes through the form identifying whether mandatory text fields have a value or not and then populates the text value of a hidden/visible error message box.
This all works fine but writing 200+ lines of codes for the same sort of task is clearly not an efficient way to do things.
For this reason I have tried to create a function to do the same thing. What I want it to do is check whether a field has a value or not and if not populate an error text field with a list of fields that failed the validation.
I can do this up to a point but I want the error message to contain the name of the field without having to define it.
I've been struggling with a way to populate the text string with the name of the field. I tried looking at the path in XML to try and extract the caption value but the best I get is "-[objectXFAObject] is blank" or undefined is blank.
This what I have so far:
------
var nameField = oField.field.caption.text.value
var errorVar = ""
function validEntry(oField){
if ((oField.rawValue == null) || (oField.rawValue == ""))
{
errorVar = "Please note" + "\n \t -" + nameField + " is blank";
form1.jsTest.errorMessag.TextField2.rawValue = errorVar;
}
else if ((oField.rawValue == null) || (oField.rawValue == ""))
{
form1.jsTest.errorMessag.TextField2.rawValue = "No Mistake";
errorVar = "";
}
}
------
The text fields have
blankField.validEntry(this)
in the exit events.
http://blogs.adobe.com/formfeed/2008/12/exclusion_groups_v40.php
It's worth reading the whole series of posts (parts 1-3).
Latest version of the script objects are in this post (as far as I know):
http://blogs.adobe.com/formfeed/2009/03/a_form_to_design_a_form.php
I've used John's scripts in several forms and they work great.