Hello rohitacmilan!
Just to ensure I'm covering all bases, note that the existence of ANY empty required field (set as User Entered - Required) will prevent the form from submitting by default.
What I believe you're getting at though is that you would like to programmatically check all required fields prior to submission so you can take a custom action. If this is the case, you will indeed need a script like the one you have displayed. After reviewing your script I found a few issues that I'll discuss after displaying the solution:
var lv_txtfld;
for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++)
{
var oFields = xfa.layout.pageContent(nPageCount, "field");
var nNodesLength = oFields.length;
for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++)
{
if (oFields.item(nNodeCount).ui.oneOfChild.className == "textEdit")
{
lv_txtfld = oFields.item(nNodeCount);
if ( (lv_txtfld.mandatory == "error") &&
(lv_txtfld.rawValue == null || lv_txtfld.rawValue == ""))
{
xfa.host.messageBox(lv_txtfld.name + " is a required field - please enter the same");
}
}
}
}
The issues were as follows:
1) The line that reads "lv_txtfld = oFields.item(nNodeCount).ui.oneOfChild.rawValue" was bombing out. What I believe was the intention here was to get a reference to the specific node we are on within our loop for ease of use in the following if statement. We should note however that we already have an array of references to all applicable nodes in the array "oFields".
2) The line that starts with "if (( !lv_txtfld.optional ) ..." was bombing out for a few reasons. First and foremost, "optional" is not a property of a form node. I believe the intention here was to check if the current node was required or not. In that case, you would normally check the "mandatory" property. A field that is required will have a "mandatory" property equivalent to the string literal "error". Secondly, the segment of the "if" clause after the "&&" appears to be written with the intent of checking the contents of the current node for a value. If that's the case we need to check the "rawValue" property. In addition to this point, we would want the second clause of our "||" statement to not have whitespace in the string literal as "" is not equivalent to " ".
3) It appears that the intent of the line within the innermost "if" statement is to display a message box to the user to let them know that an empty, required field was found. If this is the case, then we can simply use the "name" property of the current node instead of "oFields.item(nNodeCount).ui". Further, the method to display a message box is "xfa.host.messageBox(...)".
4) Although not really an "error" per se, I thought I'd point out that you don't need to use the keyword "continue" after you display the message box to the user about an empty required field. You are within a for loop at this point and it will continue to run normally until at last its test clause fails.
I hope I've been helpful! Please do let me know if you have any questions.
Take care!
Josh Boyle
jboyle@cardinalsolutions.com
Cardinal Solutions Group