Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

How to stop validation?

Avatar

Level 3

Hi everyone,

I have a form with custom validation. If the user checks a box a subform becomes visible. Only when that subform is visible a couple of its fields should be treated a required. I was able to achieve that with the script below except that all validation is triggered for that subform at the same time. I would prefer one error at a time. So if vendor1 is null the prompt alerts the user, highlights and focus on that field and no other required alerts should come up. How do I stop the validation after the first null error is triggered?

Validate Event of vendor1:

if (comparativeBids.presence == "visible" && this.rawValue == null) {

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

    this.fillColor = "255,232,230";

    xfa.host.setFocus(this);

    false;

  }

Validate Event of vendor2:

if (comparativeBids.presence == "visible" && this.rawValue == null) {

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

    this.fillColor = "255,232,230";

    xfa.host.setFocus(this);

    false;

  }

etc.

1 Accepted Solution

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

1 Reply

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"});

}