Skip to main content
ZombieLuna
Inspiring
October 19, 2018
Question

Help With Code Adjustment for Print

  • October 19, 2018
  • 1 reply
  • 340 views

I am trying to make my PDF form look for required fields that are blank and print the form as blank if the necessary fields are blank.  It is possible that I'm making it more complicated than is necessary, however I'm a neophyte with JavaScript and this is what I've found so far.

Currently, the code that I have reads as:

(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;

    }

})();

This works perfectly, and I have so few fields on the form that typing them out specifically isn't a big deal.  The problem that I'm running into is that some of the fields' visibility is dependent on a drop down selection and I need the code to disregard required fields that are hidden at print.

I tried to edit it myself with another code and create a kind of Franken-code, but that didn't work at all.

As I said before, I'm completely new at this, so any help that can be offered would be greatly appreciated!

This topic has been closed for replies.

1 reply

Inspiring
October 19, 2018

You can use the numFields property and the getNthField method  to walk the fields of a form and test to see if they have been completed. I have found that comparing the value of a field to its defaultValue​ a much more reliable method to check if a field has been completed because not all fields use a null string for their default value. For example, drop down fields use a space or other user entered string like "Select of of the following" or Check Boxes and Radio Buttons have a value of "Off" when no selection has been made.

ZombieLuna
Inspiring
October 22, 2018

I'm going to be honest, you said a while bunch of stuff I didn't understand there. Lol

The Franken-code, I was trying to make included a line from another code I found that would filter out the required fields based on visibility.  The line was this:

    if (f.type!="button" && f.required && f.display==display.visible) {

But because I don't know what I'm doing, it basically nullified the code that I input above and made it not work at all....  I'm hoping someone can help me adjust what I have left in my previous message and make it work like the code that I have that includes the line above...