Is there a way in Javascript to get the value of a field *after* the field format is applied?
Copy link to clipboard
Copied
I'm building a process that needs to validate some aspects of our forms, and this process needs to check the formatted value of the fields in the document (some of the fields may have a custom format function), not the entered value. This process will run in an application level action javascript, not document level.
e.g. a field has a custom format script 'formatCodeNumber()' which formats '1234567890' as '12-3456-78-90', i need to get '12-3456-78-90', not '1234567890'
Alternately, is there a way to get the custom format javascript code that is applied to the field (in the example above 'formatCodeNumber()')? If I can do that, I should be able to do what I need to validate that field. I can set the format via script using the field.setAction() function, but I don't see a way to get the current format script.
Copy link to clipboard
Copied
The code in an event script cannot be acquired from a script.
However, the function 'formatCodeNumber()' is defined in your document. So you have the code already.
To validate the "formatted" value, just add the validation code to the format event. Or format the value in a validation script so you can check it there.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thanks for the response, but I'm not trying to validate the fields themselves (well, in some cases I am, see date bug below), I need to determine in this script which fields are calling which functions.
The validation isn't the form data, it's validating the functionality of the form itself. I work with many forms, some of which have hundreds of fields (one has well over 500), and I need to run a script that will output data on which fields use which formats. I can do this by having my script add a document script to the document which overrides those functions, and formats the value to a descriptor to determine which script is used, and which options are passed to that function, but the script would need to be able to read the formatted value descriptor to output the data I need.
In addition to that, I also have a need in another instance to be able to validate the value as it's formatted (i.e. some browsers don't format certain dates correctly.). I wrote scripts to test a 200 year range to find the dates that are not formatted correctly, but I need to be able to say that "this value formats this way, absolutely". What I have validats what I need right now, but they technically don't validate the displayed values (I am running scripts which take a date, run it through the formatting script, then compare it to each token in the date concatenated to match the way it's supposed to appear)
These are medical forms which go through intensive regulations, and some of these regulations require proof that the forms have been tested thoroughly to verify they display the correctly entered values.
To see the date bug, create a field, add this to the field custom format:
var s = event.value
var d = new Date(s);
event.value = util.printd("mm/dd/yyyy", d)
Then open the PDF in Google Chrome on a Mac and enter 12/1/2000 as the date.
The date will format as 12/02/2000
Copy link to clipboard
Copied
For reference, this is the output of my date test script on Chrome Mac to identify the dates which are do not format or validate correctly. I'm not sure if these are testing against the exact formatting I'm using above (I may have been using a different function than the util.printd, i created that script long ago), so the problem dates may be different, but I believe they should match. The results are different between PC and Mac.
Copy link to clipboard
Copied
The features you want are not available in the Acrobat JavaScript model. You'd need to write an Acrobat plug-in or an app with a PDF library.
Also, scripts and formatting are not reliable outside of the desktop Acrobat Pro/Reader, and a few compliant PDF viewers. I would stronly suggest not allowing any PDF form to be used in a browser PDF viewer. It's possible the "Embed PDF" (web based) viewer will handle formatting correctly.
And frankly, you're questions are outside the scope of a forum. You should hire a consultant.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Unfortunately, I don't always have the luxury of telling my client that they can't use their forms in a browser; in many cases that's a requirement as their users may have browser-based systems for managing their documents. In cases where I do have that control, yes, my forms do deactivate their functionality when opened in a browser.
I have found the solution to the current task I need to do, using only Javascript, i can get the formatted value using 'getPageNthWord' and 'getPageNthWordQuads' to identify the formatted text and their location, and determine the fields in the form that encompass each word. Although it won't be as easy if the formatted text isn't what Acrobat javascript considers a single word, I will be using overriding functions in my current needs task to format the fields I need to identify using a unique one-word descriptor. And in other cases, I should be able to identify and reassemble the words from each field location to determine the formatting being used.
I have your ConvertingPageCoords_Sample.pdf to look through for working with the coordinates, so this should give me everything i need.

