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

Check to see if any field is empty

Community Beginner ,
Jun 01, 2013 Jun 01, 2013

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
85.0K
Translate
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"));

}

Translate
replies 151 Replies 151
Community Expert ,
Jul 20, 2018 Jul 20, 2018

At the end of your code add this:

else this.mailDoc({cTo: "me@server.com", cSubject: "Subject line of the email", cMsg: "Message body of the email"});

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

Why not just use the number of fields and the get nth field name with the getField to get and test each page as needed?

You will need to account for fields that do not have a value.

Translate
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
Nov 19, 2014 Nov 19, 2014

Hey, does anyone know how to make an app.alert if the required fields are all filled in. ie. one or more characters? Something like, "All required fields are filled in "

Translate
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 ,
Nov 20, 2014 Nov 20, 2014

It is the "else"  if there are no uncompleted fields. It was included in my earlier post.

Translate
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 ,
Jul 01, 2015 Jul 01, 2015

Hi Try67,

I have set your code into my pdf document (Will Print and Will Save Menu), when I go to File - Print or File - Save warning was appear "Error! You must fill in the following fields" that's clear. But, unfortunately my document was still printed and saved after that warning.

How to prevent my document if field not complete will stay not print or save ?

Quote :

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

}

Thank you

Translate
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 ,
Jul 01, 2015 Jul 01, 2015

You can't prevent that entirely. One possibility, though, is to have an error message show up on the form itself, saying it is incomplete.

Translate
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 ,
Jul 02, 2015 Jul 02, 2015

Hi Try,

Thanks for response, is it possible if we set disable print menu after alert show or data blank or what ever that inform user that he doesn't complete it?

My document already show alert message and set focus to that blank field, but after that document still printed.

Thank you Sir,

Translate
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 ,
Jul 03, 2015 Jul 03, 2015

You can if you do the printing from the script. Change the last block of code to this:

if (emptyFields.length>0) {

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

} else this.print();

Translate
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 ,
Jul 06, 2015 Jul 06, 2015

Document still print sir, and data still shown, doc should be blank. any other ways for this sir ? or did you posted / experienced for using print button in form or disable print menu in File - Print menu setting.

Thank you for your time and response

Translate
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 ,
Jul 06, 2015 Jul 06, 2015

Did you make sure to remove any other commands to print the file from the button?

And you can't disable the built-in Print command of the application.

Translate
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 ,
Jul 06, 2015 Jul 06, 2015

the print button should check all field and if all field are complete, the document will print. For other command keep on that document sir.

Sample : Your first PDF form with Scribus - Scribus Wiki

Thank you sir

Acroread unicode.png

Translate
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 ,
Jul 07, 2015 Jul 07, 2015

You can't control how that "Print Form" button works. You can only use the

WillPrint event to present an error, or even hide the fields in the file if

they're not all filled-in, so the printed result is a blank form. But you

can't prevent the file from printing entirely.

Translate
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 ,
Jul 08, 2015 Jul 08, 2015

yes, I've found the way for last issue. Thank you, for your exp.

and now, i've some issues as below :

     1. Can we set field to un-required / required = false or set as blank field when we push check button ? (If condition)

     2. Can we set some fields to un-required / required = false or set as blank field when we fill one field use text button  ? (If condition)

Translate
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 ,
Jul 09, 2015 Jul 09, 2015

Yes, all of these things are possible.

Translate
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 ,
Jul 09, 2015 Jul 09, 2015

any references for that sir?

Thank you

Translate
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 ,
Jul 09, 2015 Jul 09, 2015

What kind of condition do you want to use? What exactly do you want to do to the other field? Set it as not required? Clear its value?

Try to be a bit more specific.

Translate
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 ,
Jul 09, 2015 Jul 09, 2015

     1.

     --> I have 1 check button and I have some require fields in documents.

     --> If I click that check button, some fields modified to unrequired field

     2.    

     --> I have 1 text button and I have some require fields in documents.

     --> If I insert some character into that text button, some fields modified to unrequired field or modified other fields.

Thank you Sir

Translate
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 ,
Jul 09, 2015 Jul 09, 2015

This is the condition :  

  1.

     --> I have 1 check button and I have some require fields in documents.

     --> If I click that check button, some fields modified to be not required field

     2.    

     --> I have 1 text button and I have some require fields in documents.

     --> If I insert some character into that text button, some fields modified to be not required field or modified other fields or clear value, etc.

Thank you Sir

Translate
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 ,
Jul 10, 2015 Jul 10, 2015

For the check-box, as the MouseUp script use this code:

if (event.target.value=="Off") {

     this.getField("Field1").required = true;

     this.getField("Field2").required = true;

     this.getField("Field3").required = true;

} else {

     this.getField("Field1").required = false;

     this.getField("Field2").required = false;

     this.getField("Field3").required = false;

}

For the text field, use this code as the custom Validation script:

if (event.value=="") {

     this.getField("Field1").required = true;

     this.getField("Field2").required = true;

     this.getField("Field3").required = true;

} else {

     this.getField("Field1").required = false;

     this.getField("Field2").required = false;

     this.getField("Field3").required = false;

}

Translate
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 ,
Jul 10, 2015 Jul 10, 2015

hello,

Im using the following in order to unhide a signature button if all fields are filled, it is working correctly for text fields in documents and i dont need it to check check boxes, however i do need it to check radio buttons have all been selected.

i'm using the following:

this.getField("Document Sign").hidden = true
var emptyFields = [];

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

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

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

          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 all required Fields:\n");
     //removed list as it has over 200 fields and if clicked to early produces a pop up that is too big to close

}
else{this.getField("Document Signed").hidden = false}

I am assuming the only section that will have to be changed is checkbox in bold above as radio buttons also have off as their default state, however I cant seem to find the exact type name for radio buttons.

Translate
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 ,
Jul 10, 2015 Jul 10, 2015

Use this;

|| ((f.type=="checkbox" || f.type=="radiobutton") && f.value=="Off"))

Translate
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 ,
Jul 10, 2015 Jul 10, 2015

cheers that has worked perfectly! I was using just "radio" as an alternate to "checkbox".

Translate
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 ,
Jul 10, 2015 Jul 10, 2015

Thank you sir try67‌ , you're very helpful..

Translate
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 ,
Jul 13, 2015 Jul 13, 2015

Hi Guys

In the below script It very useful & it's work perfectly but in the script (text fields & check fields) only it consider other than Dropdown box and List box  are not considering. Can you please help me out how to include those dropdown & list box in this script


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

}

Translate
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
Mar 07, 2016 Mar 07, 2016

Is there anywhere is this tread that specifies how to only highlight required fields that were not completed after using the submit form option? or does that have to be done through scripting at the field level?

Translate
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