Skip to main content
Participant
November 24, 2022
Answered

Script to change text field's fill color depending on text not working in Adobe Reader

  • November 24, 2022
  • 2 replies
  • 1561 views

Hi 

I prepared a document with a form text field. The custom validation script for each field is as follows: 


if (event.value=="No Stock")

event.target.fillColor = color.red;

else if (event.value=="Medium")

event.target.fillColor = color.yellow;

else if (event.value=="High")

event.target.fillColor = color.green;

else if (event.value=="")

event.target.fillColor = color.transparent;

 

Basically, it is working fine in Adobe Reader  DC Pro for me and my collegues

But in all other Adobe Reader versions (e.g. Adobe Reader DC), the coloring is not permanent only when you hover over the field and click on it you can see it.  

And I don't understand what I am doing wrong! 

Thanks already for the help and suggestions

This topic has been closed for replies.
Correct answer bebarth

It seems your runtimeHighlight property is set to true. You can use this script in document level:

app.runtimeHighlight = false;

or use this script:

if (app.runtimeHighlight) app.runtimeHighlight = false;
if (event.value=="No Stock") event.target.fillColor = color.red;
else if (event.value=="Medium") event.target.fillColor = color.yellow;
else if (event.value=="High") event.target.fillColor = color.green;
else event.target.fillColor = color.transparent;

 I modifyed a bit your script because what happens if the text is anything else???

You will maybe need to set the runtimeHighlight property to true after that (or not) !!! That can be done when you close the file for example.

app.runtimeHighlight = true;

 

2 replies

bebarth
Community Expert
bebarthCommunity ExpertCorrect answer
Community Expert
November 24, 2022

It seems your runtimeHighlight property is set to true. You can use this script in document level:

app.runtimeHighlight = false;

or use this script:

if (app.runtimeHighlight) app.runtimeHighlight = false;
if (event.value=="No Stock") event.target.fillColor = color.red;
else if (event.value=="Medium") event.target.fillColor = color.yellow;
else if (event.value=="High") event.target.fillColor = color.green;
else event.target.fillColor = color.transparent;

 I modifyed a bit your script because what happens if the text is anything else???

You will maybe need to set the runtimeHighlight property to true after that (or not) !!! That can be done when you close the file for example.

app.runtimeHighlight = true;

 

Participant
November 24, 2022

Simple and nice! This works well after I set the app.runtimehighlight=true; it works strictly as intended! Thank you so much. Also, the addition makes sense; I did not think about it that someone would write anything else inside the text fields, haha! Just great! 

try67
Community Expert
Community Expert
November 25, 2022

Be aware, though, that this changes this setting for all documents the user will open, not just for yours. It might be a good idea of informing them of that change, or (even better) to get their permission for doing it.

Nesa Nurani
Community Expert
Community Expert
November 24, 2022

You have fields highlight turned on.

Participant
November 24, 2022

Thank you a simple way to solve it is if I have a pool of people and can control their properties! Thanks:)