I am using the following function to populate an error subform in a form. It's works the way it should except when there are no errors (errMsg.length === 0).
Changing the ErrorsField presence to hidden causes the for block not to execute. The alert still comes up. I have somewhat fixed the problem by moving the ErrorsField.presence = "hidden" command to the PreSubmit event but I really don't understand why it won't work this way. I would really appreciate any help.
function PopulateErrors() {
ErrorsField.ListBox1.clearItems();
if (errMsg.length > 0) {
ErrorsField.presence = "visible";
for (var i = 0; i < xfa.layout.pageCount(); i++) {
xfa.resolveNode("form1.Page1[" + i + "].EmailSubmitButton1").presence = "hidden";
xfa.resolveNode("form1.Page1[" + i + "].Submit").x = "3.375in";
}
for (var i = 0; i < errMsg.length; i++) {
ErrorsField.ListBox1.addItem(errMsg[i].message);
}
ErrorsField.ListBox1.caption.value.text.value = errMsg.length === 1 ? errMsg.length + " error found. Please correct the fields listed below." : errMsg.length + " errors found. Please correct the fields listed below.";
xfa.host.setFocus(ErrorsField.GoToFirst);
}
else {
ErrorsField.presence = "hidden";
for (var i = 0; i < xfa.layout.pageCount(); i++) {
xfa.resolveNode("form1.Page1[" + i + "].EmailSubmitButton1").presence = "visible";
xfa.resolveNode("form1.Page1[" + i + "].Submit").x = "2.375in";
}
xfa.host.messageBox("No errors found. You may submit your survey by clicking on the green submit button.", "Error check", 3);
}
}