Copy link to clipboard
Copied
I have a pdf form that has required text fields and radio buttons. Once the user has filled out the form I've created a button that will check to see if all the required fields have been filled out, if yes then send an email, and then close the form without saving. If no, an app alert pops up and allows you to fill in the missing information. The app.alert works for the text fields but not the radio buttons. If the radio button is the only thing not filled out, I get the default error and then it skips the email portion and closes without saving the pdf. I have one set of radio buttons (qty of 3) called "group". Here is the JavaScript. Can someone please help.
var requiredFields = new Array();
for (var i = 0; i < this.numFields; i++)
{
var fName = this.getNthFieldName(i);
var f = this.getField(fName);
if (f.type!="button" && this.getField(fName).required && (this.getField(fName).value == null || this.getField(fName).value == ''))
{
requiredFields[requiredFields.length] = fName;}}
var error = "Please complete the following fields: \n\n";
for (j=0; j < requiredFields.length; j++)
{
if (requiredFields
{
error = error + requiredFields
var f2 = this.getField(requiredFields
f2.setFocus();
}
}
if (requiredFields.length > 0) {
app.alert(error);
} else {
this.submitForm ({
cURL:"mailto:none@none.com",
cSubmitAs: "PDF",
})
this.closeDoc(true);
}
The default value of a radio-button group when no button is selected is "Off", not null.
Copy link to clipboard
Copied
The default value of a radio-button group when no button is selected is "Off", not null.
Copy link to clipboard
Copied
I changed both nulls to off and it doesn't work as well as changing each one separately and it didn't work. I guess I don't understand what I'm suppose to change.
Copy link to clipboard
Copied
It's not "off" but "Off". JS is case-sensitive.
Copy link to clipboard
Copied
Sorry, I changed them to "Off" and it didn't work. It says Off is not defined.
Copy link to clipboard
Copied
Did you include the double-quotes around it?
Copy link to clipboard
Copied
Maybe not Now it works. Thanks for your help!
Copy link to clipboard
Copied
Here is the updated code:
var requiredFields = new Array();
for (var i = 0; i < this.numFields; i++)
{
var fName = this.getNthFieldName(i);
var f = this.getField(fName);
if (f.type!="button" && this.getField(fName).required && (this.getField(fName).value == "Off" || this.getField(fName).value == ''))
{
requiredFields[requiredFields.length] = fName;}}
var error = "Please complete the following fields: \n\n";
for (j=0; j < requiredFields.length; j++)
{
if (requiredFields
{
error = error + requiredFields
var f2 = this.getField(requiredFields
f2.setFocus();
}
}
if (requiredFields.length > 0) {
app.alert(error);
} else {
this.submitForm ({
cURL:"mailto:none@none.com",
cSubmitAs: "PDF",
})
this.closeDoc(true);
}
Notice the "Off" is just in the first if statement. null is needed in the second if statement for the error message to display the required fields that are still blank.
Copy link to clipboard
Copied
A field value will never be equal to null, so it's misleading to compare a field value with it.
If a user enters the string "Off" in a required text field, it will be considered incomplete by that code.
If you have any dropdowns, list fields, or radio buttons, you'll probably want to check their values against their default values to see if a valid selection has been made.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now