Skip to main content
Known Participant
September 9, 2020
Question

Required field alert upon submission

  • September 9, 2020
  • 1 reply
  • 6001 views

I have set several fields in my form to required. If the field is not completed upon submission the Adobe acrobat error message appears stating that at least one field is empty.

Is there a way to specify which fields are empty? Specify a list of empty fields the user needs to go back and complete? Instead of just a general statement.

If so how would I go about doing that? This is my 1st form I am completing.

This topic has been closed for replies.

1 reply

Known Participant
September 9, 2020

Okay, I was able to find the following script and it works, but 1st I get the default general warning saying 1 of the required fields is not complete. Followed by a 2nd warning displaying exactly which fields need to be filled in.

How do I remove the 1st warning?

Here is the script I used by placing it in the actions for the submit button.

var emptyFields = [];

for (var i=0; i<this.numFields; i++) {

var f= this.getField(this.getNthFieldName(i));

if (f.type!="button" && f.required ) {

if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);

}

}

if (emptyFields.length>0) {

app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));

}

try67
Community Expert
September 9, 2020

You have to use only the JS action, not both JS and Submit Form.

Add the following to the end of the script (use the actual email address to submit it to, of course):

 

else this.mailDoc({cTo: "me@server.com"});

try67
Community Expert
September 11, 2020

Okay,

I've spent hours trying to figure out why the grant field will not validate. I looked at the JavaScript I'm not sure what I'm even looking for. I erased every reference in the JavaScript that referenced the grant field and not to work. Even when it was erased some of the commands still worked. Not sure why that happened. Any suggestions would be greatly appreciated. I am so close to getting this exactly how I need it.


This is the error message I'm getting:

 

TypeError: this.getField("grayimage") is null
16:Field:Mouse Up

 

It happens because there's no field with that name, and it causes the rest of the code to not work.