Avatar

Correct answer by
Level 3

Just in case someone can find this useful... I resolved the issue above by adding all validation conditions in the click event of my submit button using a switch statement instead of if. The break in the cases prevents the next field from being validated until the previous has passed its own validation - that means one alert at a time instead.

var canSubmit = true

var myDoc = event.target;

var mail_message = "Insert Default Message Text Here"

var mail_subject = "E-mail Subject Here"

//begin validation of subform:

switch (comparativeBids.presence == "visible") {

case PRForm.comparativeBids.comparativeBidsTable.Row1.vendor1.rawValue == null    :

     app.alert("Please enter a vendor name on line 1 of the Comparative Analysis section.");

    PRForm.comparativeBids.comparativeBidsTable.Row1.vendor1.fillColor = "255,232,230";   

    xfa.host.setFocus(PRForm.comparativeBids.comparativeBidsTable.Row1.vendor1);

    canSubmit = false;

    //reset other alerts

    PRForm.comparativeBids.comparativeBidsTable.Row1.price1.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row2.vendor2.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row2.price2.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row3.vendor3.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row3.price3.fillColor = "255,255,255";

    PRForm.comparativeBids.justification.fillColor = "255,255,255";

    break;

   

case PRForm.comparativeBids.comparativeBidsTable.Row1.price1.rawValue == null    :

    app.alert("Please enter a price on line 1 of the Comparative Analysis section.");

    PRForm.comparativeBids.comparativeBidsTable.Row1.price1.fillColor = "255,232,230";

    xfa.host.setFocus(PRForm.comparativeBids.comparativeBidsTable.Row1.price1);

    canSubmit = false;

    //reset other alerts

    PRForm.comparativeBids.comparativeBidsTable.Row1.vendor1.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row2.vendor2.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row2.price2.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row3.vendor3.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row3.price3.fillColor = "255,255,255";

    PRForm.comparativeBids.justification.fillColor = "255,255,255";

    break;

case PRForm.comparativeBids.comparativeBidsTable.Row2.vendor2.rawValue == null    :

      app.alert("Please enter a vendor name on line 2 of the Comparative Analysis section.");

    PRForm.comparativeBids.comparativeBidsTable.Row2.vendor2.fillColor = "255,232,230";

    xfa.host.setFocus(PRForm.comparativeBids.comparativeBidsTable.Row2.vendor2);

    canSubmit = false;

    //reset other alerts

    PRForm.comparativeBids.comparativeBidsTable.Row1.vendor1.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row1.price1.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row2.price2.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row3.vendor3.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row3.price3.fillColor = "255,255,255";

    PRForm.comparativeBids.justification.fillColor = "255,255,255";

    break;

   

case PRForm.comparativeBids.comparativeBidsTable.Row2.price2.rawValue == null    :

     app.alert("Please enter a price on line 2 of the Comparative Analysis section.");

    PRForm.comparativeBids.comparativeBidsTable.Row2.price2.fillColor = "255,232,230";

    xfa.host.setFocus(PRForm.comparativeBids.comparativeBidsTable.Row2.price2);

    canSubmit = false;

    //reset other alerts

    PRForm.comparativeBids.comparativeBidsTable.Row1.vendor1.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row1.price1.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row2.vendor2.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row3.vendor3.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row3.price3.fillColor = "255,255,255";

    PRForm.comparativeBids.justification.fillColor = "255,255,255";

    break;   

case PRForm.comparativeBids.comparativeBidsTable.Row3.vendor3.rawValue == null    :

     app.alert("Please enter a vendor name on line 3 of the Comparative Analysis section.");

    PRForm.comparativeBids.comparativeBidsTable.Row3.vendor3.fillColor = "255,232,230";

    xfa.host.setFocus(PRForm.comparativeBids.comparativeBidsTable.Row3.vendor3);

    canSubmit = false;

    //reset other alerts

    PRForm.comparativeBids.comparativeBidsTable.Row1.vendor1.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row1.price1.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row2.vendor2.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row2.price2.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row3.price3.fillColor = "255,255,255";

    PRForm.comparativeBids.justification.fillColor = "255,255,255";

    break;   

case PRForm.comparativeBids.comparativeBidsTable.Row3.price3.rawValue == null    :

     app.alert("Please enter a price on line 3 of the Comparative Analysis section.");

    PRForm.comparativeBids.comparativeBidsTable.Row3.price3.fillColor = "255,232,230";

    xfa.host.setFocus(PRForm.comparativeBids.comparativeBidsTable.Row3.price3);

    canSubmit = false;

    //reset other alerts

    PRForm.comparativeBids.comparativeBidsTable.Row1.vendor1.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row1.price1.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row2.vendor2.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row2.price2.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row3.vendor3.fillColor = "255,255,255";

    PRForm.comparativeBids.justification.fillColor = "255,255,255";

    break;   

   

case PRForm.comparativeBids.justification.rawValue == null    :

     app.alert("Please explain your vendor choice under the Comparative Analysis section.");

    PRForm.comparativeBids.justification.fillColor = "255,232,230";

    xfa.host.setFocus(PRForm.comparativeBids.justification);

    canSubmit = false;

    //reset other alerts

    PRForm.comparativeBids.comparativeBidsTable.Row1.vendor1.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row1.price1.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row2.vendor2.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row2.price2.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row3.vendor3.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row3.price3.fillColor = "255,255,255";

    break;

   

default:    //reset all alerts

    PRForm.comparativeBids.comparativeBidsTable.Row1.vendor1.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row1.price1.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row2.vendor2.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row2.price2.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row3.vendor3.fillColor = "255,255,255";

    PRForm.comparativeBids.comparativeBidsTable.Row3.price3.fillColor = "255,255,255";

    PRForm.comparativeBids.justification.fillColor = "255,255,255";

}

//if subform is hidden or passes conditions above then submit form

if (canSubmit) {

    myDoc.submitForm({cURL:"mailto:;?cc=user@domain.com;&subject="+mail_subject+"&body="+mail_message,

        bEmpty: true,        // Post all fields (true), or do Not post all fields (false)  

        cSubmitAs:"PDF",    // Post PDF format

        cCharset:"utf-8"});

}

View solution in original post