Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

JS for Document Will Print Action when required fields are incomplete

New Here ,
Nov 03, 2016 Nov 03, 2016

Hello,
I've been reviewing several threads in hoping to find an answer to this question, but Ive been unsuccessful.

http://forums.adobe.com/thread/1276533?tstart=0

https://forums.adobe.com/thread/1223607

I am looking for help in writing a JavaScript that will result in all fields being printed blank if the user fails to respond to all of the required fields.

I tried this one, but I received syntax errors that I do not understand:

//var i, val, bNotComplete = false; 

var aFields = ["REQ2", "REQ3"]; 

for (i = 0; i < aFields.length; i += 1) { 

val = getField(aFields).valueAsString; 

if (!val) { 

bNotComplete = true;  app.alert("Not all required fields are complete, so the form will print blank.", 3); 

break; 

for (i = 0; i < numFields; i += 1) { 

getField(getNthFieldName(i)).display = bNotComplete ? display.noPrint : display.visible; 

})(); 

I am working with Adobe Acrobat XI standard.

I am very new to this and appreciate any help I can get.

TOPICS
PDF forms
867
Translate
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
LEGEND ,
Nov 03, 2016 Nov 03, 2016

If you are going to copy & paste code, you need to copy all the relevant code. Your code ends with  "();" which is a call to a self defined function but your code does not start with the identifying the  "function" object.

Where did you place this code?

You should realize that drop down and list fields may have a non-selected value of " " or a space; check boxes and radio buttons have a value of "Off" when no item in a group of buttons or a single check box has not been selected.

Your code if placed in the document action of "Will print" will only run after the User Interface (UI) Print appears. It also will stop testing fields when the first required field is encountered and not inform the user of the incomplete form fields.

The following might be the correct code or it at least has the obvious missing statements.

(function()
{
var val, bNotComplete = false;
var aFields = new Array("REQ2", "REQ3");

// console.println("Number of fields: " + aFields.length); // debugging statement;

for (var i = 0; i < aFields.length; i++) {
  val = this.getField(aFields).valueAsString;

//  console.println(i + " field name: " + aFields + " value = " + val + "length: " + val.length); // debugging statement;

  if (!val) {
   bNotComplete = true;
   app.alert("Not all required fields are complete, so the form will print blank.", 3);
   break;
  } // val not empty
} // end for array of fields;
for (var i = 0; i < numFields; i++) {
  this.getField(this.getNthFieldName(i)).display = bNotComplete ? display.noPrint : display.visible;
}
})();

I have added some commented out statements that trace the running of the code if the comment marker is removed.

Translate
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
New Here ,
Nov 03, 2016 Nov 03, 2016

Thanks gkaiseril.

I am putting the code to the document will print option.

I pasted the code from your post above and it did not work.

I need the code to check all of the required fields (11 fields) and if any are missing, the form should print with blank values..

Sorry, I have no idea what i'm doing.. I appreciate your help.

Translate
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
LEGEND ,
Nov 03, 2016 Nov 03, 2016

I have no idea what "Did not work" means.

Are there any errors messages popping up?

Are there any error messages the JavaScript console?

Does the printer print a piece of paper without fields?

Translate
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
New Here ,
Nov 03, 2016 Nov 03, 2016
LATEST

Syntax error:

SyntaxError: illegal character

2:Doc:Will Print

ReferenceError: fromValue is not defined

1:Doc:Did Print

SyntaxError: illegal character

2:Doc:Will Print

ReferenceError: fromValue is not defined

1:Doc:Did Print

And the entire form still prints..

Translate
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