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
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"});
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"));
}
Copy link to clipboard
Copied
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?