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.
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
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.
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
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?
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
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"));
}
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!
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!
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.
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?
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.
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
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.
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!
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)
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"));
}
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) {
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
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"));
}
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
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?
Copy link to clipboard
Copied
Not if you use the comparison of the field's value to the field's default value.
// required fields;
var aRequiredFields = new Array("Text1", "Text2",
"Check Box3", "Group1", "List Box5", "Dropdown6");
// messages for non-completed fields;
var aMessage = new Array();
aMessage["Text1"] = "Complete Text1";
aMessage["Text2"] = "Complete Text2";
aMessage["Check Box3"] = "Complete Check Box3";
aMessage["Group1"] = "Complete Radio Button Troup1";
aMessage["List Box5"] = "Complete List Boxt5";
aMessage["Dropdown6"] = "Complete Dropdown6";
// array of non-compleeted field names;
var aNotCompleted = new Array();
// loop through fields and finding fields whose value si the same as their default value;
for(var i = 0; i < aRequiredFields.length; i++) {
// clear the field fill color;
this.getField(aRequiredFields).fillColor = color.transparent;
if(this.getField(aRequiredFields).value == this.getField(aRequiredFields).defaultValue) {
// log field name into array;
aNotCompleted.push(aRequiredFields);
// set the field's fill color;
this.getField(aRequiredFields).fillColor = color.red;
} // not completed
} // end loop field names
if(aNotCompleted.length != 0) {
var cMsg = "Complete following " + aNotCompleted.length + " fields:";
for(var i = 0; i < aNotCompleted.length; i++) {
// load field message into error message
cMsg += "\r"+ aMessage[aNotCompleted];
}
app.alert(cMsg, 1, 0);
} else {
// actions to complete when all required fields completed.
app.alert("Conradualtions, all fields completed", 3, 0);
}
Copy link to clipboard
Copied
hello, my document appear information "You must fill filed xxxx" but after that message why my document still print ya? Pls help .
Thanks
dewe14
Copy link to clipboard
Copied
I was able to do this by also adding the javascript to a new action on a Print button.
Mouse down>run the javascript
Mouse up>Print
It would still print if you go to "File>Print" but at least it required the fields to be filled in before the print button would work.
Copy link to clipboard
Copied
If you add the print command as a part of the JS code then you could abort it entirely (when the button is used) if not all the fields are filled-in.
Copy link to clipboard
Copied
I realized after I posted this that it did not work. I could click okay and still save or print. Any suggestions? I probably need an "else if" statement at the end of the script.
Copy link to clipboard
Copied
It all has to be done in a single script. One action can't interfere with another one.
If you post your code I could let you know how to do it.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 "
Copy link to clipboard
Copied
It is the "else" if there are no uncompleted fields. It was included in my earlier post.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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,
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
Yes, all of these things are possible.
Copy link to clipboard
Copied
any references for that sir?
Thank you
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Use this;
|| ((f.type=="checkbox" || f.type=="radiobutton") && f.value=="Off"))
Copy link to clipboard
Copied
cheers that has worked perfectly! I was using just "radio" as an alternate to "checkbox".
Copy link to clipboard
Copied
Thank you sir try67 , you're very helpful..
Copy link to clipboard
Copied
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"));
}