Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Change text fields from white to transparent after filled in

Participant ,
Oct 14, 2021 Oct 14, 2021

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?

TOPICS
JavaScript , PDF forms
1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Oct 14, 2021 Oct 14, 2021

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

 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 14, 2021 Oct 14, 2021

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;

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 14, 2021 Oct 14, 2021

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;

    }
  }

}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 14, 2021 Oct 14, 2021

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 14, 2021 Oct 14, 2021

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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 15, 2021 Oct 15, 2021
LATEST

This worked well for me. Thank you! 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines