• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Check to see if any field is empty

Community Beginner ,
Jun 01, 2013 Jun 01, 2013

Copy link to clipboard

Copied

I have a pretty large document that has over 200 text/check boxes. What I want to do is create a button that makes a pop-up warning for any blank fields in the entire document.

Right now the only way I've seen to do this is using javascript using an array of every field and checking them 1 by 1 in a for-loop. I would like to avoid this as the array requires you to type the title of each field so with 200+ fields it becomes quite tedious typing them all in.

Using Acrobat XI Pro, thanks.

TOPICS
Acrobat SDK and JavaScript

Views

68.3K

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

correct answers 1 Correct answer

Community Expert , Jun 01, 2013 Jun 01, 2013

You can use something like this:

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

}

Votes

Translate

Translate
replies 151 Replies 151
Community Expert ,
Jun 01, 2013 Jun 01, 2013

Copy link to clipboard

Copied

You don't necessarily need an array with the names of the fields, but you do need some way of determining which fields to control...

So do you want to control all of the fields in the file? Or all of the required ones?

Votes

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
Community Beginner ,
Jun 01, 2013 Jun 01, 2013

Copy link to clipboard

Copied

All required fields, out of the 200+ only about 10 dont need to be filled.

GKaiseril: Thats what Im doing now. I have an array:

var a1 = new Array(getField("box1"), getField("text1"));

for (number of items in a1)

   check if empty

      popup box if empty

the problem is typing in the array "box1", "text1" since I have over 200 fields to type in

Votes

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
Community Expert ,
Jun 01, 2013 Jun 01, 2013

Copy link to clipboard

Copied

You can use something like this:

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

}

Votes

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
Community Beginner ,
Jun 01, 2013 Jun 01, 2013

Copy link to clipboard

Copied

Thanks a lot Giliad D! That script worked perfectly.

For anyone else who is trying to implement this heres how:

Create a button

Right click the button and go to properties -> Actions tab

Trigger:Mouse Up

Action: Run JavaScript

-> Add...

Copy and paste Giliad D's code

->ok -> close

Select the fields you want required by right clicking the fields and selecting the "Set as Required Field" option

Save and done!

Votes

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
New Here ,
Feb 05, 2016 Feb 05, 2016

Copy link to clipboard

Copied

Wondered id it's possible to attach the Javascript to the button from within InDesign CC and then have another action afterwards (go to next page)

Votes

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 ,
Feb 05, 2016 Feb 05, 2016

Copy link to clipboard

Copied

Many have found that creating forms in InDesign or Create Suite products other than Acrobat can be problematic. It is best to create the forms and scripts in Acrobat.

Votes

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
Community Beginner ,
Feb 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

Any idea what the trigger would be if I don't want them to be able to download it blank?

Votes

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
New Here ,
Aug 05, 2013 Aug 05, 2013

Copy link to clipboard

Copied

So the code above works very well on text fields, but doens't work on radio button fields. Is there code that works on radio button fields?

Thanks!

Votes

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 05, 2013 Aug 05, 2013

Copy link to clipboard

Copied

For radio buttons and check boxes in Acrobat you find the unselected items by testing for a value of "Off". In LiveCycle you need to know the unselected value for each field.

Votes

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
New Here ,
Aug 16, 2013 Aug 16, 2013

Copy link to clipboard

Copied

oh wow! this is a perfect script! but it runs only when the button is clicked right? I want it to run when "print" icon is clicked or file is saved with empty fields.

is it possible?

Votes

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 16, 2013 Aug 16, 2013

Copy link to clipboard

Copied

you can put the script in the "Will Print" document action. But you will not be able to stop the printing so you will need to workout your approach on how to handle that next piece.

Also the script will not detect uncompleted drop down boxes or list boxes.

Votes

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
New Here ,
Aug 16, 2013 Aug 16, 2013

Copy link to clipboard

Copied

how do i do that? before today I did not even know I could add scripts to pdf files wow!

my main problem i posted in other thread is this

"I am a graphic designer and am using Adobe Acrobat X pro to create fillable invitations, labels and such

what I want is that my client cannot print the file without filling "required" field.....

Also , no one can edit it even if they open via acrobat pro

or maybe some way I can protect my images from printing without text?

One more question

How can i make a floating textbox, which increases if text increases and is not fixed size?"

I was led to this thread which sort of solves the problem ,

so umm what does it mean by

"But you will not be able to stop the printing so you will need to workout your approach on how to handle that next piece." ? ?

Can you guide me through?

Thanks so much!

Marie

Votes

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 16, 2013 Aug 16, 2013

Copy link to clipboard

Copied

You appear to be taking this question in new directions.

You might want to start a new thread and not usurp someone else's thread.

Votes

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
New Here ,
Aug 16, 2013 Aug 16, 2013

Copy link to clipboard

Copied

oh i was not doing that i did start a new thread here http://forums.adobe.com/thread/1276533?tstart=0

and i was directed to this thread!

Votes

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
New Here ,
Nov 11, 2013 Nov 11, 2013

Copy link to clipboard

Copied

This is very helpful. Thank you.

What code would I need to add if I want to display a validation message that says "Form successfully completed". (in addition to the code provided by Gilad D)

Votes

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
New Here ,
Apr 01, 2014 Apr 01, 2014

Copy link to clipboard

Copied

I've used your script for verifying that required fields are filled out, and it works great. But I have some fields that are required, but may be hidden based on a user selection (checkbox). Can the script be modified to ignore hidden fields? Thanks!

Gilad D (try67) wrote:

You can use something like this:

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

}

Votes

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
Community Expert ,
Apr 01, 2014 Apr 01, 2014

Copy link to clipboard

Copied

Yes. Change this line:

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

To this:

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

Votes

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
New Here ,
Apr 01, 2014 Apr 01, 2014

Copy link to clipboard

Copied

Votes

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
New Here ,
Sep 11, 2014 Sep 11, 2014

Copy link to clipboard

Copied

Thanks for this script! What needs to be added to do the following:

If the above script shows no errors, email: a@b.com.

Votes

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
Guest
Sep 11, 2014 Sep 11, 2014

Copy link to clipboard

Copied

Add this to the end of the script:

else this.mailDoc({

cTo: "a@b.com",

});

Votes

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
Guest
Sep 14, 2014 Sep 14, 2014

Copy link to clipboard

Copied

its a great script. I have some drop down menus / list boxes that has a default value in that starts with the word "Select" eg Select Cost Code or Select Work Location to prompt the user to click on the arrow to make a selection.

Can the code be changed to accomodate both empty fields and fields with a value in it that starts with the word Select

Also can the code be changed to accomodate the empty or Select fields border /edge or text change color to say red to visually identify which fields require completion?

Votes

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
Guest
Sep 21, 2014 Sep 21, 2014

Copy link to clipboard

Copied

To highlight required fields in red, modify the script in line 6 as follows:

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

f.strokeColor = color.red;   //Highlights the required fields in red

emptyFields.push(f.name);
    }
}

if (emptyFields.length>0) {
     app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));
}

Votes

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
Guest
Oct 17, 2014 Oct 17, 2014

Copy link to clipboard

Copied

Hi Michael,

Thanks for the suggested code, it works well and highlights the borders of empty fields in red nicely.

Is there any way of the code be written show it only highlights empty fields, fields that show a value with the word "Select...." in them and only visible fields?

Regards,

Michael

Votes

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
Guest
Oct 19, 2014 Oct 19, 2014

Copy link to clipboard

Copied

Things are getting a bit complicated, as this requires multiple "if" statements.

Can you please clearly state which fields you want to be highlighted by the script? Empty fields only? Fields that are required only? Fields with "Select" in them? Text fields only or all fields?

Votes

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