These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

App Alert for Multiple Blank required fields

Bond007AE
Registered: Nov 2 2011
Posts: 6
Answered

Hi Everyone,
 
I'm new to this forum and would like to seek your valuable help in my project.
 
I created an acrobat form with required fields and upon clicking on configured button, I put a validation script that pops an alert if there are blanks on the required fields. Can you please help me construct a script that will pop an alert populated with all the fields that supposed to be non-blank. for example
 
Please review and complete the required fields:
Missing information on Name
Missing information on Age
etc
etc
 
I currently have this:
 
var RequiredFields = new Array(2);
RequiredFields[0] = "Name";
RequiredFields[1] = "Age";

var AlertMsg = new Array(2);
AlertMsg[0] = "Missing information on Name";
AlertMsg[1] = "Missing information on Age";
 
var bSuccess = true;
var emptyTest = /^\s*$/;
var fieldCount = RequiredFields.length;
var fld = 0;

for (var i=0; i
Send email
  
Appreciate all your help...

My Product Information:
Acrobat Pro 10.1, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
Something like this...

  1. var errorMessage = "";
  2. for (var i=0; i<RequiredFields.length; i++) {
  3. var f = this.getField(RequiredFields[i]);
  4. if (emptyTest.test(f.value)) {
  5. errorMessage += AlertMsg[i] + "\n";
  6. bSuccess = false;
  7. }
  8. }
  9. if (bSuccess) {
  10. // send email
  11. } else {
  12. app.alert(errorMessage);
  13. }
You should be aware that this will work with text fields, but if you have combo-boxes, radio-buttons or check-boxes that you want to verify you'll need to adjust it because they have different values when empty.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Bond007AE
Registered: Nov 2 2011
Posts: 6
Thank you. That was quick...
Bond007AE
Registered: Nov 2 2011
Posts: 6
BTW, where do I insert the fix statement "Please review and complete the required fields:"


try67
Expert
Registered: Oct 30 2008
Posts: 2398
Set it as the initial value of errorMessage (add a "\n" at the end for the line break).

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Bond007AE
Registered: Nov 2 2011
Posts: 6
I tried this:

< for (var i=0; i
< var f = this.getField(RequiredFields[i]);>< if (emptyTest.test(f.value)) {>
< errorMessage += "Please review and complete the required fields:" >+ "\n" +
< AlertMsg[i] + "\n";>
< bSuccess = false;>but I got repeated fixed statement on the alert message:

Please review and complete the required fields:
Missing information on Name
Please review and complete the required fields:
Missing information on Age


How to make it look like this:

Please review and complete the required fields:
Missing information on Name
Missing information on Age


TY
try67
Expert
Registered: Oct 30 2008
Posts: 2398
If you want to paste code, do it inside of < code > < / code > (drop the spaces).

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Bond007AE
Registered: Nov 2 2011
Posts: 6
The fixed statement works, can you share the code if ther are combo box/drpdown list?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You need to change the initial value of errorMessage. So change line #1 in the code I posted earlier to:
var errorMessage = "Please review and complete the required fields:\n";

Regarding combo-boxes: The issue there is that they always have a value selected, so the way to do it depends on how you set it up. I posted some time ago a generic function that verifies different types of fields. Study the code and it would help you solve this problem.
Have a look here: http://acrobatusers.com/forum/javascript/make-field-required-if-amount-entered-separate-field#comment-82518

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com