Skip to main content
ZombieLuna
Inspiring
October 25, 2018
Question

Print form as blank of required fields blank

  • October 25, 2018
  • 0 replies
  • 249 views

Good morning,

I have two codes that I've used to do similar functions, but I'm having trouble combining them.

This code:

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.valueAsString==f.defaultValue) { 

            f.strokeColor = color.red; 

            emptyFields.push(f.name); 

        } else { 

          f.strokeColor = color.transparent; 

        } 

    } 

 

if (emptyFields.length>0) { 

    app.alert("YOU MUST COMPLETE THE FOLLOWING FIELDS:\n" + emptyFields.join("\n")); 

}

checks for blank required fields and alerts the user that there is information missing, but still allows to form to print or save with the data that has been input.

Then this code:

(function () {

    var i, val, bNotComplete = false;

    var aFields = ["Sale Amount", "Office Refund Amount", "Office Credit Amount", "Client Name", "Client ID", "Ad Number", "Dispute Type", "Dispute Reason Text", "Office Dropdown1", "Office Dropdown2", "Dispute Notes", "Prepared By"];

    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;

    }

})();

which also checks for blanks, but prints the form blank if the required fields aren't complete.

What I'm trying to do is take the discrimination from the first code, which looks at if the required fields are visible or not, and the ability of the first code to look at the entirety of the form, not just specific fields, and combine it with the second code's ability to print or save all the fields in the form as blank if anything information is missing.

But I don't have a clue what I'm doing.  Please help!  I would appreciate it a great deal!

This topic has been closed for replies.