Copy link to clipboard
Copied
I have the prompt text figured out using this script taken from this forum: Is there a way to add instructional text to my text field that will disappear when clicked? (PDF For...
// Custom Format script for text field
if (!event.value) {
event.value = "Instructional text goes here";
event.target.display = display.noPrint;
} else {
event.target.display = display.visible;
}
Is their a way to change the prompt text's size and make it different from the type size I have set for them to fill out in the form. I want the type size of the prompt to be smaller than what size they use to fill it out.
Copy link to clipboard
Copied
Why yes there is, and your code is already setup for adding it. The "display" is a property of the text field object, and it is being set one way for the help text, and another way when the user enters the text. The text size is also a property of the text field object and it can be set in the same way.
// Custom Format script for text field
if (!event.value) {
event.value = "Instructional text goes here";
event.target.display = display.noPrint;
event.target.textSize = 12;
} else {
event.target.display = display.visible;
event.target.textSize = 9;
}
You could also set the size on the keystroke event, or the OnFocus event, to capture the moment the user starts typing in the field.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
This is a form text field.
Copy link to clipboard
Copied
So is that a "yes - it can be done" Or "No - it cannot be done"
Copy link to clipboard
Copied
I don't know.
Copy link to clipboard
Copied
Yes, it can be done. You would need to write a script to iterate over all the fields in the file (using numFields and getNthFieldName), check which ones are text fields (using getField and the type property) and then apply the code to them as the Format script (using the setAction method).
Copy link to clipboard
Copied
Hello just chiming in here to ask a question, can I add multiple forms like this in one document? LIke if I did an instructional text for Your Phone Number, could I then use the same script for say Your Email, and just change the intructional text for a different field?
Copy link to clipboard
Copied
Do you mean you want to use the same string for both fields, and be able to edit it in one place, and have it automatically apply to all of them?
Copy link to clipboard
Copied
Yes, you can do it that way. Or you could turn the code into a document level function, where the text is an input to the function, then call that function in all of the "format" scripts where it is needed.
Note that this script replaces any built-in formatting. So, if you want the field formatted in some specific way, then you'll need to create a custom formatting script to add to the code.
Use the Acrobat JavaScript Reference early and often


-
- 1
- 2