Copy link to clipboard
Copied
I have pieced together Javascript to validate that required forms are filled, if filled, prompt a save as with new name suggestion, and then email submission. It functions properly on Mac Adobe Acrobat Pro DC, but on Windows 10 Adobe Reader 2017, I received on the Javascript debugger "TypeError: f is null 7:Field:Mouse Down"
I have it set on a submit button, Mouse Down, run a JavaScript. It may look pretty messy as I am very novice to this!
Any idea why this would be happening from the script below?
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.value !== 0) || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);
}
}
if (emptyFields.length>0) {
app.alert("At least one required field was empty. Fill out the required fields before saving:\n" + emptyFields.join("\n"));
} else {
var newFileName =
("TheFeed_DigitalContentBrief_") +
this.getField("Brand").valueAsString + "_" + this.getField("Market").valueAsString + "_" + this.getField("BriefingDate").valueAsString + ".pdf";
app.response("Please copy the text below and use it as the new file-name:","", newFileName);
app.execMenuItem("SaveAs");
this.mailDoc({bUI:false,cTo:"General - TEAMS: The Feed LATAM <042c8d45.nestle.onmicrosoft.com@emea.teams.ms>",cSubject:"New Content Brief from " + this.getField("Market").value + " for " + this.getField("Brand").value, cBody:"Attached new Digital Content Brief, please review."})
}
After this line:
var f= this.getField(this.getNthFieldName(i));
Add this:
if (f==null) continue;
Copy link to clipboard
Copied
After this line:
var f= this.getField(this.getNthFieldName(i));
Add this:
if (f==null) continue;
Copy link to clipboard
Copied
Thank you so much!! It now works to continue the process for saving and submitting, but doesn't give notice for fields required being unfilled. Is there another way you know of coding this function?
Copy link to clipboard
Copied
This code should work (I wrote it...), but change this line:
if ((f.type=="text" && f.value=="" && f.value !== 0) || (f.type=="checkbox" && f.value=="Off"))
To:
if (f.valueAsString==f.defaultValue)
Copy link to clipboard
Copied
Yes, that worked! I have been referencing your code pieces I've found to put this together! Thank you so much for your expertise!
One last question! Is there a way to stop the next function if the user hits cancel on the save window instead of continuing to submission?
Copy link to clipboard
Copied
Only if it's a part of the same script, not if it's a separate command.
Copy link to clipboard
Copied
ok! Thank you for all of your help!