Skip to main content
llblumire
Participant
May 14, 2019
Answered

getField updating AFTER validation

  • May 14, 2019
  • 2 replies
  • 1375 views

I'm just starting out trying to get my head wrapped around acrobat javascript to try and automate some things, and thought I should try and so some simple tests.

So, I have the following function.

function Alert () {

  console.println(doc.getField("PC").value);

}

And in the Validate tab for the "PC" field, I have set

"Run a custom validation script:"

Alert()

Yet when I look in the console, the value it prints is the value BEFORE I make a change. For example, if the value in the PC box is "Bob" and I change it "Alice", then it will print "Bob" instead of "Alice".

How can I get the new value for the field in the validate script?

This topic has been closed for replies.
Correct answer Joel Geraci

The issue is I want the script to run only once on edit, rather than whenever any field is updated. Is there a way to achieve this outside of a validator script?


The custom format script is the last to run. It doesn't have to be used to change the appearance of the field, it can do anything that you need it to do and runs after the validation script (if any) and after the field value is committed. I use it to do all sorts of stuff that has nothing to do with field formatting.

2 replies

Legend
May 14, 2019

If you only want to run it when a field is updated, why would you use the validation script at all, since we know it hasn't been updated?

try67
Community Expert
Community Expert
May 14, 2019

Use event.value instead of this.getField("...").value .

llblumire
llblumireAuthor
Participant
May 14, 2019

Is there no more universal way to get this value. I am attempting to build a document model stored in global

(function () {

  global.model = new Object();

  Object.defineProperty(global.model, "pc", {

    get: function () {

      return doc.getField("PC").value;

    },

    set: function (value) {

      return doc.getField("PC").value = value;

    }

  })

})();

And would like it to always get the most up to date version of a field so that I can use a common interface inside all validation and calculate functions.

(doc is defined to be the global this variable of an Acrobat JS script)

Legend
May 14, 2019

That is the most up to date value of a field; in that method you are dealing with some typed information which is not yet stored into the field. That's the point of the validation script: it protects the field from bad data, and at that point the event is only typing. Calculate functions, by contrast, are dealing with the values in OTHER fields which are already stored.

You do need to study in detail the description of each method. You may find a few simple rules that can be applied, but universality isn't a a strength of the design.