Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

How to validate required fields before executing menu item ("Save As") using cutom Javascript?

Avatar

Level 1

Hi,

Sorry, I am new to PDF Development. I tried creating PDF using Acrobat XI Pro. During creation, I have encountered issues in running custom JavaScript. The requirement is to validate all the required fields before saving the PDF. I tried using the following scripts to validate the said required fields. But, it's not working.

Option 1: If the field is null, a message box will appear.

if(this.getfield("textbox") = null){

app.alert("required");

}

else {app.execMenuItem("SaveAs");}

Option 2: If the field is required, a message box will appear.

var f = this.getField("textbox");
f.required = true;

if(f = true)
{
app.alert('required');
}
else
{
app.execMenuItem("SaveAs");
}

The scripts mentioned above are not working. I wanted to validate the required fields before saving the PDF.

In addition, I tried validating each field using the following script:

f = getField(event.target.name)

if (f.value.length == 0)

    {

    f.setFocus()

    //Optional Message - Comment out the next line to remove

    app.alert("This field is required. Please enter a value.")

    }

When I open the PDF, the script is working. However, when the message box pops out, the "OK" button is not working as expected. The message box is not closing. I tried opening the form in a site in different Java versions (like 7-11 and 7-67). It's working in version 7-67. I tried upgrading the Java version from 7-11 to 7-67. Still, it doesn't work.

I would appreciate your feedback on this matter.

0 Replies