Copy link to clipboard
Copied
I have several text fields that I want to be white but once the user fills them in I need them to be transparent. I've tried several things I have seen here on the forum but can't get any of them to work. Help?
Copy link to clipboard
Copied
Another example of a much more simpler and elegant custom format script (in my opinion) that fits in a single line would be:
event.target.fillColor = event.target.value.length > 0 ? color.red : color.transparent;
For this other example I used a variation of the following script :
var f = event.target; /* field that the event occurs at */
f.target.textColor = event.value < 0 ? color.red : color.black;
Which is explained in greater detail in the Adobe Acrobat SDK JavaScript API,
JavaScript™ for Acrobat® API -- "Reference color methods" on page 164
Copy link to clipboard
Copied
This won't work for numbers though, also change 'red' to 'white' and change place transparent : white.
EDIT: Try like this: event.target.fillColor = event.target.value != "" ? color.transparent : color.white;
Copy link to clipboard
Copied
This may be achieved in different ways with a JavaScript script.
In my example below I used a Custom Format Script:
if (event.willCommit) {
var f = event.target;
var g = event.value;
if (g =="") {
f.fillColor = color.white;
} else {
if (g !="") {
f.fillColor = color.transparent;
}
}
}
Copy link to clipboard
Copied
Another example of a much more simpler and elegant custom format script (in my opinion) that fits in a single line would be:
event.target.fillColor = event.target.value.length > 0 ? color.red : color.transparent;
For this other example I used a variation of the following script :
var f = event.target; /* field that the event occurs at */
f.target.textColor = event.value < 0 ? color.red : color.black;
Which is explained in greater detail in the Adobe Acrobat SDK JavaScript API,
JavaScript™ for Acrobat® API -- "Reference color methods" on page 164
Copy link to clipboard
Copied
This won't work for numbers though, also change 'red' to 'white' and change place transparent : white.
EDIT: Try like this: event.target.fillColor = event.target.value != "" ? color.transparent : color.white;
Copy link to clipboard
Copied
This worked well for me. Thank you!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now