Check specific fields aren't empty

Participant ,
Aug 19, 2019 Aug 19, 2019

Copy link to clipboard

Copied

I have 13 individual fields on a document that cannot be blank. Due to the way the form is used, I have added a button at the bottom that says 'validate content' and it runs the following when the button is pressed. This works well, but it's obviously checking each field individually and giving separate error messages.

How do I get it to check all 13 fields at once and give the error message as one list of empty fields and mark the fields with a coloured border?

  var patternEmpty = /^\s*$/;

  var strMissing = "";

  if(patternEmpty.test(this.getField("User.USER_EMPLOYEENUMBER").value))

     strMissing = "User Employee Number";

  else

  { // All is ok, submit the data

     console.println("All form data ok");

  }

  if(strMissing.length)

  {// Got an error

     app.alert("Missing Form data in field: Code V.1 " + strMissing);

  }   

  var patternEmpty = /^\s*$/;

  var strMissing = "";

  if(patternEmpty.test(this.getField("O.aff").value))

     strMissing = "O.aff";

  else

  { // All is ok, submit the data

     console.println("All form data ok");

  }

  if(strMissing.length)

  {// Got an error

     app.alert("Missing Form data in field: " + strMissing);

  }   


 

TOPICS
Acrobat SDK and JavaScript, Windows

Views

334

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Aug 19, 2019 Aug 19, 2019

Copy link to clipboard

Copied

Place the names of the fields in an array and the use a loop to check all the items in that array, keeping a tab of which ones are empty.

At the end of the loop, display your error message and color the empty fields.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 19, 2019 Aug 19, 2019

Copy link to clipboard

Copied

In all honesty, I still don't understand Javascript and take my hat off to all those of you who do but I thought I'd try and figure this out using your guidance above....

I found a script that you (try67​)​ wrote previously (https://forums.adobe.com/message/5371436#5371436#5371436 ) and it works fabulously for what I want but is there any way I can change the names of the fields without actually changing the names of the fields?

As you can see below, I have some random field names that mean nothing to the person completing the document, but are crucial for the document to pull the correct info in when it's merged. Eg. User.USER_EMPLOYEENUMBER has to stay as is, but I'd like the error message to say 'Code V1 User Name'

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 19, 2019 Aug 19, 2019

Copy link to clipboard

Copied

You can display the tooltip (userName).

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Aug 19, 2019 Aug 19, 2019

Copy link to clipboard

Copied

As Bernd suggested, using the tooltip text is a good idea. Or you could create a parallel array with the text to show for each field, and then use those values in your error message instead of the field names.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 20, 2019 Aug 20, 2019

Copy link to clipboard

Copied

LATEST

Fields have the property "defaultValue" which contains the value of the field used to populate the field upon reset. Note that not all fields will be empty. This property lets one check if the field has been updated form the initial opening state.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines