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.
1 Correct answer
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"));
}
Copy link to clipboard
Copied
Hi,
I have a form, in which some of the Text field are made required. I need to validate those fields. It is a normal form which does not have button to submit.... It is just a save from tool bar. What should I do to Validate? Please guide me
Thanks,
SBS
Copy link to clipboard
Copied
is it livecycle or acrobat?
Copy link to clipboard
Copied
acrobat
Copy link to clipboard
Copied
Do you have phone and email fields and you want to make sure the user enters correct format or did you just want to make sure regular text fields are filled out?
Copy link to clipboard
Copied
regular text fields
Copy link to clipboard
Copied
You can use the code provided above as the file's Will Save event. However, keep in mind you can't actually prevent the file from being save in the code.
Copy link to clipboard
Copied
Hi
Could you please send your PDF to me
It will help to explain you in detailed
Copy link to clipboard
Copied
From: srinivasanr92755262 <forums_noreply@adobe.com>
To: Suma Subbu <sbaguraiah@yahoo.com>
Sent: Monday, November 9, 2015 7:11 PM
Subject: Check to see if any field is empty
Check to see if any field is empty created by srinivasanr92755262 in PDF Forms - View the full discussionHi Could you please send your PDF to me It will help to explain you in detailed If the reply above answers your question, please take a moment to mark this answer as correct by visiting: https://forums.adobe.com/message/8159101#8159101 and clicking ‘Correct’ below the answer Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: Please note that the Adobe Forums do not accept email attachments. If you want to embed an image in your message please visit the thread in the forum and click the camera icon: https://forums.adobe.com/message/8159101#8159101 To unsubscribe from this thread, please visit the message page at , click "Following" at the top right, & "Stop Following" Start a new discussion in PDF Forms by email or at Adobe Community For more information about maintaining your forum email notifications please go to https://forums.adobe.com/thread/1516624. |
Copy link to clipboard
Copied
I realize that this is an old question, but...
I have tried using this code in my document form in a "Print Button" and I've tried it in the "Document Will Print" Action.
In both scenarios I do not get an error stating that the JS is incorrect however with empty required fields in the document, the action goes straight to "Print" without giving me the message.
Any ideas on why?
Copy link to clipboard
Copied
If you have any field that is formatted to "Number" you need to access the field using the "valueAsString" propertry since the actual value is in the IEEE Floating Point notation and does not have a string length.
it should be noted that all required fields have a property of "defautValue" that can be compared to a field's value as a string to see if a field has a value other than the default value of the field. The a form is set to the default values by resetting the form so the default value should be the value of a field before completion. This approach also works for dropdown list, combo list, check boxes, and radio buttons.
Dropdown list and combo boxes have a default value of a space unless the field is populated by JavaScript or some other user entry. Check boxes and radio buttons have a value of "Off" unless the user specifies the field is checked by default. So these fields will have a length of at least 1 character when not completed so the length of the value might not be the best general approach.
It might be helpful have a public link to the form or a sample of the form that does not work so others can see exactly what is going on.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
It will be helpful if you let us know where your Print button is located...
Copy link to clipboard
Copied
I have a print button at the second to last page but I don't think I put the JS in that button.
I sure I put it in "Document Action" > "Document Will Print"
Copy link to clipboard
Copied
From that event you can't prevent the file from being printed. Only from a
button that you added yourself and that calls the print command through a
script.
On Fri, Jan 29, 2016 at 9:54 PM, cycling-wv <forums_noreply@adobe.com>
Copy link to clipboard
Copied
Upon opening the PDF and looking at the JavaScript console, I have the following error:
TypeError: this.getField(...) is null
1:Document-Level:Two Line OK Box
I see no such field in your form.
When I ran your script I got the following error in the JavaScirpt console:
TypeError: f is null
4:Doc:Will Print
When looking at the list of field names sorted alphabetically I see fields with na mes like " to be Acauired..." and " to be Determined...". at the top of the field name list because they all start with a space. I was under the impression that field names needed to start with an alphabetic or numeric value.
Once these errors were fixed you script ran through all the form fields and popped an alert.
I did not go through and attempt to fill all the fields to see what happened,
This should be enough to get you started.
Copy link to clipboard
Copied
Can this script only be run from a "button" or can it be used with the "Document Will Print" Action?
I ask this because I can get the error message to come up when I use the "Print Document" button on the last page if I insert the script there, but when the script is inserted in the "Will Print" I do not get the error message.
I know I can't (nor is it even a good idea to) prevent someone from printing. I simply want to let them know that some required fields are not completed.
Copy link to clipboard
Copied
I would writethis as an action that returns a value so that woulcould determine if there any incomplete fields and then cll that function as an action for a buttn or will print, etc.
Copy link to clipboard
Copied
I know this is an old thread, but I have a similar problem and can't get the javascript to work. (I posted about it here, but haven't gotten any responses): How do I make it so blank required fields are highlighted when the user clicks the Submit button?​ )
I have the required fields (which are both text and radio buttons) set as "required" in their properties). I need for any unfilled required text fields or radio buttons to be listed, called out, or highlighted in some way when the user clicks on the submit button so they know what they've missed. Right now, all it will do is show this message:
Currently, ALL the required fields are highlighted red (which apparently is standard and not changeable in Adobe Acrobat Pro DC).
This is the code that I'm using:
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"));
}
Copy link to clipboard
Copied
This code works as it should and is EXTREMELY Helpful to this beginner.
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"));
}
However one thing i was wondering, how would we code an additional thing in here of the following:
Once the check is done and everything is good to go, then display a print form button. But keep the print form button hidden until the check produces no error. This would be really good to have in my case. Any help would be very much appreciated.
Copy link to clipboard
Copied
You're welcome!
To do that change the last part of the code to this:
if (emptyFields.length>0) {
app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));
this.getField("PrintButton").display = display.hidden;
} else this.getField("PrintButton").display = display.visible;
And of course create a (hidden) button called "PrintButton" that prints the file when clicked.
Copy link to clipboard
Copied
I must be doing something very wrong, because I copy and pasted the code and still am receiving the stock required fields error message:
This is how the properties are set up:
I'm sure it's something simple, but I'm at a loss as to what I'm doing wrong!
Copy link to clipboard
Copied
My reply was not to you, but to the message after yours. Anyway, you should remove the "Submit a form" command. It needs to be done using the script.
Copy link to clipboard
Copied
EXCELLENT! THAT WORKED FOR 99% OF WHAT IN NEEDED. RIGHT NOW THE ONLY ISSUE IS THIS. ONCE THE CHECK BUTTON IS CLICKED, AND ONCE THE FORMS ARE ALL FILLED IN AND IT'S ALL GOOD TO GO, I CLICK THE CHECK BUTTON AND IT DISPLAYS A LARGE HIDDEN PRINT BUTTON OVER THE ENTIRE PAGE THAT I WANT TO PRINT WHICH IS WHAT I DO WANT. THE ISSUE IS THAT THE PRINT BUTTON PRINTS OVER THE SHEET LOL. THERE IS NO SELECTION FOR HIDDEN AND NOT PRINTABLE IN THE BUTTON OPTIONS.
SUGGESTION ON HOW TO END UP PRINTING THE FORM WITHOUT THE "HIDDEN TO UN-HIDDEN BUTTON" AFTER ALL FORM FIELDS ARE FILLED OUT?
Copy link to clipboard
Copied
If you want to make the PrintButton field visible on the screen but not printable, replace display.visible in the code with display.noPrint .
And please don't write in all-caps, it's quite distracting.
Copy link to clipboard
Copied
I tried using that code, but when I test it out, nothing happens (I removed the Submit a Form command from the properties).

