Copy link to clipboard
Copied
I have set several fields in my form to required. If the field is not completed upon submission the Adobe acrobat error message appears stating that at least one field is empty.
Is there a way to specify which fields are empty? Specify a list of empty fields the user needs to go back and complete? Instead of just a general statement.
If so how would I go about doing that? This is my 1st form I am completing.
Copy link to clipboard
Copied
Okay, I was able to find the following script and it works, but 1st I get the default general warning saying 1 of the required fields is not complete. Followed by a 2nd warning displaying exactly which fields need to be filled in.
How do I remove the 1st warning?
Here is the script I used by placing it in the actions for the submit button.
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 have to use only the JS action, not both JS and Submit Form.
Add the following to the end of the script (use the actual email address to submit it to, of course):
else this.mailDoc({cTo: "me@server.com"});
Copy link to clipboard
Copied
Thank you. When I use the submit form button you have an export format option. I opted to export PDF. Will the above code do the same thing?
Copy link to clipboard
Copied
Yes.
Copy link to clipboard
Copied
Thank you again, but I have one more follow-up question.
With the code this.mailDoc({cTo: "me@server.com"});
I have seen where people add true and false to it. For example:
this.mailDoc(true, "yourname@address.com")
I found something that said the true and false refers to bUI, but what is that?
Copy link to clipboard
Copied
It's whether or not the email is sent silently (if there's no UI -- User Interface -- it's sent silently), but you can't set it as false unless you can install a script on the local computer of each user, and even then it won't be completely silent.
Copy link to clipboard
Copied
It is not checking to see if my radio buttons are required, so I tried adding to the code but it didn't work. Here's what I did
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.type=="radio" && 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"));
}
else this.mailDoc({cTo: "sample@sample.org"});
what am I doing wrong
Copy link to clipboard
Copied
This is an outdated version fo the code. Change this line:
if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off") || (f.type=="radio" && f.value=="Off"))
To:
if (f.defaultValue==f.valueAsString)
And it will work with any field type.
Copy link to clipboard
Copied
Thanks. My radio buttons are still not showing up in my warning message.
Copy link to clipboard
Copied
Strange. Are they set as required? Can you share the file with us if so?
Copy link to clipboard
Copied
I am sure it's something I did. There's a lot going on and I'm sure I did something that is conflicting with this issue. I shared the file above.
Copy link to clipboard
Copied
For some reason (my guess is it's because it was created with InDesign) the value of this field is currently "false", instead of "Off". Reset the form, save it and then try again.
Copy link to clipboard
Copied
If you go to the radio button under donationgrant and look at the actions for charitable donations you will see the custom script I added. Maybe something there is causing the problem. I do have a bunch of values changed. And I do have some value set to false and off.
Copy link to clipboard
Copied
If that is the problem do I just change the word false to off
Copy link to clipboard
Copied
Can you set the default value in InDesign? If so, that's bad... It should be set to "Off" to work properly in Acrobat.
Copy link to clipboard
Copied
Also, how do I reset the form?
Copy link to clipboard
Copied
Tools - Prepare Form - More - Clear Form.
Copy link to clipboard
Copied
In my custom actions in Adobe I edited the following code:
this.getField("grant").value= false;
should I be using off instead of false? If so how do I that?
Copy link to clipboard
Copied
I did not know about clearing the form. That worked!
Copy link to clipboard
Copied
I spoke too soon. It works but if I change options, then it does not. I'm sure it has to do with the off versus false. How do I change the value in the code from false to off?
Copy link to clipboard
Copied
To clear the field you can use this code:
this.getField("grant").value= "Off";
Or even:
this.resetForm(["grant"]);
Copy link to clipboard
Copied
I am almost there. I've got my cost center radio but in working, but not my grant radio button. Below is the code I use for my custom actions. I know this is causing the issue but I can't figure out why.
this.getField("grant").required = false;
this.getField("grant").readonly = true;
this.resetForm(["grant"]);
this.getField("Cost Center").value= "Off";
this.getField("customeracct").required = false;
this.getField("customeracct").readonly = true;
this.getField("customeracct").fillColor = ["RGB",.66,.66,.66];
this.getField("grant").fillColor = ["RGB", .6688, .66, .66];
if(event.target.value == "CHARITABLE DONATION") {
this.getField("charitabledonation1").value="On";
this.getField("charitabledonation2").value="On";
this.getField("charitabledonation1").fillColor = ["RGB", 1, 1, 1];
this.getField("charitabledonation2").fillColor = ["RGB", 1, 1, 1];
this.getField("grayimage").display = display.hidden;
this.getField("graysquare").display = display.visible;
this.getField("marketing").setFocus();
this.getField("customeracct").readonly = true;
this.getField("customeracct").required = false;
this.getField("customeracct").fillColor = ["RGB",.66,.66,.66];
this.getField("customeracct").fillColor = ["RGB",.66,.66,.66];
this.getField("grant").fillColor = ["RGB", .6688, .66, .66];
this.getField("grant").required = false;
this.getField("Cost Center").required = true;
this.getField("grant").value= "Off";
this.getField("grant").readonly = true;
}
if(event.target.value == "GRANTPROMOTION") {
this.getField("Cost Center").required = true;
this.getField("charitabledonation1").value="Off";
this.getField("charitabledonation2").value="Off";
this.getField("charitabledonation1").fillColor = ["RGB",.66,.66,.66];
this.getField("charitabledonation2").fillColor = ["RGB",.66,.66,.66];
this.getField("customeracct").fillColor = ["RGB", 1, 1, 1];
this.getField("grant").fillColor = ["RGB", 1, 1, 1];
this.getField("customeracct").required = true;
this.getField("customeracct").readonly = false;
this.getField("grant").required = true;
this.getField("grant").readonly = false;
this.getField("grayimage").display = display.visible;
this.getField("grayimage").readonly = true;
this.getField("graysquare").display = display.hidden;
}
do you see where my mistake is?
Copy link to clipboard
Copied
Where did you place the code?
Copy link to clipboard
Copied
In the top right hand corner of the form you have to choose between charitable donation and grant/promotion . I placed all of that code in the actions.
Essentially if charitable donations is selected you do not need to answer the radio buttons on the right-hand side (choose GL account) but if you select grant/promotion then you have to.