Skip to main content
Known Participant
August 19, 2019
Question

Check specific fields aren't empty

  • August 19, 2019
  • 2 replies
  • 2064 views

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

  }   


 

This topic has been closed for replies.

2 replies

Inspiring
August 20, 2019

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.

try67
Community Expert
Community Expert
August 19, 2019

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.

jlehaneAuthor
Known Participant
August 19, 2019

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'

Bernd Alheit
Community Expert
Community Expert
August 19, 2019

You can display the tooltip (userName).