Expand my Community achievements bar.

AEM forms designer: Individual subform field validation issue- email submit button ( preSubmit event ) checks all fields in all subforms instead of only a specific subform

Avatar

Level 1
In AEM forms designer, I have a two subforms. Each subform has text fields, a signature field and an email submit button. Some text fields are mandatory in each subform. 
Clicking on the email submit button of one subform should check whether mandatory fields in that specific subform have been filled. I have a validation script in a Script Object called 'validationUtils'. The path to this Script object is: form1.#variables[0].validationUtils. 
The validation method in this Script Object is this: 
 
// method to validate if mandatory fields in the form element or section are filled. It returns true or false with colouring 
function validateMandatoryFields(fieldPaths, subformContext) { 
  var allFilled = true; 
   for (var i = 0; i < fieldPaths.length; i++) { 
    var field = xfa.resolveNode(fieldPaths[i]); 
      if (field === null || field.rawValue === null || field.rawValue === "") { 
         allFilled = false; // Mandatory field is not filled 
            field.border.edge.color.value = "255,0,0"; // Set red border color 
            field.border.edge.thickness = "0.5pt"; // Set border thickness 
     } else { 
           field.border.edge.color.value = "0,0,0"; // Reset border color to black 
           field.border.edge.thickness = "0.5pt"; // Set border thickness 
    } 
  } return allFilled; // All mandatory fields are filled
 
I call this function in the preSubmit event of the email submit button in each subforms
 
Subform1 path: form1.Page2.Sign_and_submit.EmailSubmitButton::preSubmit:form - (JavaScript, client) 
 
// Define mandatory field paths for subform 1 
 
var mandatoryFieldPathsSubform1 = [ 
  "xfa.form.form1.Page1.Credentials.member_name", 
  "xfa.form.form1.Page1.Credentials.member_email", 
  "xfa.form.form1.Page1.Credentials.member_id", 
  "xfa.form.form1.Page1.Goals.Goal_table.Row1.DropDownList1", 
  "xfa.form.form1.Page1.Goals.Goal_table.Row1.Description1", 
  "xfa.form.form1.Page1.Goals.Goal_table.Row1.Measure1", 
  "xfa.form.form1.Page1.Goals.Goal_table.Row1.Start_date", 
  "xfa.form.form1.Page1.Goals.Goal_table.Row1.Due_date" 
  ]; 
 
  var validatedSubform1 = validationUtils.validateMandatoryFields(mandatoryFieldPathsSubform1, "subform1"); 
  var signatureFieldSubform1 = xfa.resolveNode("form1.Page2.Sign_and_submit.SignatureField1"); 
   if (!validatedSubform1) { 
      xfa.host.messageBox("At least one of the fields was empty. Please fill in the required fields (highlighted) before continuing.", "Validation Error", 3); 
      signatureFieldSubform1.access = "readOnly"; 
      xfa.event.cancelAction = true; 
   } else { 
      signatureFieldSubform1.access = "open"; 
       var oStateSubform1 = event.target.getField("form1.Page2.Sign_and_submit.SignatureField1").signatureValidate(); 
        if (oStateSubform1 != 4) { 
          xfa.host.messageBox("Please sign the form before submitting.", "Validation Error", 3); 
          xfa.event.cancelAction = true; 
       } else { 
     xfa.event.cancelAction = false; 
  } 
   
and for subform2: form1.Page2.Agree_and_resolve.PartTwo.EmailSubmitButton::preSubmit:form - (JavaScript, client) 
   
   //check if all mandatory fields in the start cycle section of the form are filled 
   
    var mandatoryFieldPathsSubform2 = [ 
  "xfa.form.form1.Page2.Agree_and_resolve.PartTwo.destination_zip", 
  "xfa.form.form1.Page2.Agree_and_resolve.PartTwo.destination_id", 
  "xfa.form.form1.Page2.Agree_and_resolve.PartTwo.destination_timezone" 
]; 
 
var validatedSubform2 = validationUtils.validateMandatoryFields(mandatoryFieldPathsSubform2, "subform2"); 
var signatureFieldSubform2 = xfa.resolveNode("form1.Page2.Agree_and_resolve.PartTwo.SignatureField2"); 
if (!validatedSubform2) { 
    xfa.host.messageBox("At least one of the fields was empty. Please fill in the required fields (highlighted) before continuing.", "Validation Error", 3); 
    signatureFieldSubform2.access = "readOnly"; 
    xfa.event.cancelAction = true; 
 } else { 
    signatureFieldSubform2.access = "open"; 
    var oStateSubform2 = event.target.getField("form1.Page2.Agree_and_resolve.PartTwo.SignatureField2").signatureValidate(); 
      if (oStateSubform2 != 4) { 
        xfa.host.messageBox("Please sign the form before submitting.", "Validation Error", 3); 
        xfa.event.cancelAction = true; 
     } else { 
    xfa.event.cancelAction = false; 
  } 
The relevant fields are checked, but right now clicking on one email submit button in one subform checks all fields in both subforms. What did I miss?
 
Topics

Topics help categorize Community content and increase your ability to discover relevant content.

0 Replies