Custom Format for PDF Fields
A custom format script can be used to display something in the field prior to data entry.
PDF text fields can be programmed to only accept input in a specific format. The format tab of the field properties has a dropdown with a list of five built-in formats and one place to enter a custom format script:
Number
Percentage
Date
Time
Special
Custom
The number format has several options including currency symbols, separator style, and number of decimal places. The date, time, and special formats also have several options. These options actually contain custom format scripts combined with custom keystroke scripts that aren’t seen in the properties and operate behind the scenes.
In Using JavaScript To Add JavaScript to a PDF Part 2 I described how to find these custom scripts and set them programatically using the setAction method.
Get the course above, and a suite of automation tools for FREE with a Professional subscription.
Custom Format Scripts
A custom format script can be used to display something in the field prior to data entry. The format is not the value of the field. So the field can appear to display a value without actually having a value. For example, I have seen text fields on forms with text that says something like "Please enter your name". The form designer simply entered this text as the default value of the field, so Please enter your name is actually the value of the field. When users click into that field they would have to highlight all the text and start typing in order to replace it. Tabbing into the field instead would automatically highlight all the text.
What if you wanted the field to display text before the field has a value, and replace the text with the value entered by the user? You would simply write a custom format script that says if this field does not have a value, display this value. Before you click or tab into a field formatted this way, the default text is present. It disappears when the focus is on the field. Whatever you type replaces the default text. If you tab out or click elsewhere without typing a value, the original text reappears.