Adobe PDF Form Confirmation Prompt Ignores User Input

New Here ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

I am new to javascript, and am trying to make a "relatively" simple form that allows for users to input information, verifies it, confirms they are done, hides any extra fields and buttons, makes the file read only except for the submit button, and then displays the 'submit" button.

 

I am using Adobe Acrobat Pro DC Version 2022.001.20169 on a PC.

 

For the most part everything seems to be working perfectly except for one detail.  The form gets filled out, they click on the button to "certify" it, the script checks to ensure everything is completed, prompts them for any missing information, and then asks if they are sure they want to continue.  Up to this point, no issues.

 

My issue is that no matter what they choose, Yes or No, it still makes the form read only, prepares it for submission, etc.  This is the code that I have now.  I am sure it is not pretty, but my only training is google so far:

 

This is the code for the mouse up action on my button:

//verify all fields completed
 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.valueAsString==f.defaultValue) emptyFields.push(f.name);
     }
}

//notify user of incomplete fields
if (emptyFields.length>0) {
     app.alert("Please complete the following fields:\n" + emptyFields.join("\n"));
}

//if all fields complete notify user and make form read only
else {

//confirm making form read only
if(4==app.alert("This action will make the form read only.\nDo you want to continue",1,2));

//if yes then make read only and prepare for submit
this.finalize();
}

//This is my document level script for finalize():
function finalize()
{
     app.alert("Complete!");
for(var i = this.numFields - 1; i > -1; i--)
{
var fieldName = this.getNthFieldName(i);
this.getField(fieldName).readonly=true;
{
this.getField("Submit").readonly=false;
this.getField("Submit").display = display.visible;
this.getField("Attach_File").display = display.hidden;
this.getField("Certified").display = display.visible;
this.getField("Certify_Now").display = display.hidden;
}}}

 

 Any help is appreciated.

TOPICS
Create PDFs , How to , JavaScript , PDF forms

Views

27

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 26, 2022 Jul 26, 2022

Copy link to clipboard

Copied

LATEST

Hi,

 

This bit of your code doesn't look right

if(4==app.alert("This action will make the form read only.\nDo you want to continue",1,2));

//if yes then make read only and prepare for submit
this.finalize();

 

I think it should be

if(4==app.alert("This action will make the form read only.\nDo you want to continue",1,2)){
  //if yes then make read only and prepare for submit
  this.finalize();
}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines