Skip to main content
Participant
Jul 31, 2023 3:03 AM UTC
Answered

Formatting code for forms - allowing for mistakes

Hi all,

I found a useful code for changing fill and font colors based off a value.
I've got this working; e.g.

else if(event.value == "A"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 255/255, 0/255, 0/255];}

 

I'm trying to add code allowing for user typos/mistakes.

I added a clear form button, this works.
However, when re-entering the correct value, it doesnt detect the correct  command.
e.g

 

user types A (gets the above)

user deletes the A, types B but the field doesnt detect;

 

else if(event.value == "B"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}

 

I tried adding the below that i found to the start but doesnt work. 

if(event.value == ""){
event.target.textColor = color.black
event.target.fillColor = color.transparent;}

 

The form will be a basic 5 field template, they can fill and print/stick to a file.
Variable A

VariableB

VariableC

VariableD

User Name

 

Full code:

if(event.value == ""){
event.target.textColor = color.black
event.target.fillColor = color.transparent;}
else if(event.value == "A"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 255/255, 0/255, 0/255];}
else if(event.value == "B"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}
else if(event.value == "C"){
event.target.textColor = color.black
event.target.fillColor = ["RGB", 255/255, 255/255, 0/255];}
else if(event.value == "D"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 185/255, 255/255];}
else if(event.value == "E"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 64/255, 64/255, 64/255];}
else if(event.value == "F"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}
else if(event.value == "G"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 64/255, 0/255, 0/255];}
else if(event.value == "H"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 162/255, 255/255, 0/255];}
else if(event.value == "I"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 255/255, 110/255, 0/255];}
else if(event.value == "J"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 128/255, 0/255, 255/255];}
else if(event.value == "K"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 255/255, 0/255, 0/255];}
else if(event.value == "L"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}
else if(event.value == "M"){
event.target.textColor = color.black
event.target.fillColor = ["RGB", 255/255, 255/255, 0/255];}
else if(event.value == "N"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 128/255, 0/255, 255/255];}
else if(event.value == "O"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 185/255, 255/255];}
else if(event.value == "P"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 64/255, 64/255, 64/255];}
else if(event.value == "Q"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}
else if(event.value == "R"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 255/255, 26/255, 146/255];}
else if(event.value == "S"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 64/255, 0/255, 0/255];}
else if(event.value == "T"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 255/255, 110/255, 0/255];}
else if(event.value == "U"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}
else if(event.value == "V"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}
else if(event.value == "W"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}
else if(event.value == "X"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}
else if(event.value == "Y"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 128/255, 0/255, 255/255];}
else if(event.value == "Z"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}

 

I've attached the trial form as it stands

Thanks in advance for any help!

This topic is closed to new replies. Start a new post to keep the conversation going.
Bernd Alheit
Bernd AlheitCorrect answer
Community Expert
Jul 31, 2023 7:56 AM UTC

It works when you open the form in Adobe Acrobat or Acrobat Reader.

5 replies

Participant
Aug 22, 2024 6:49 PM UTC

Peter, 


This is really awesome. Would be greatful if you can share the final document. I am trying to create an audit form and this could be a life saver. 

Translate
Nesa Nurani
Community Expert
Community Expert
Aug 22, 2024 6:56 PM UTC

You can always describe what you need so we can help you.

Translate
philthedon
Participant
Sep 2, 2024 5:09 PM UTC

Hi Nesa, I am a designer trying to figure out a way amend this Java script for an image field so that the fillColor = color.white is a specific RGB value. At the moment I can't get it to work. (I am clueless on code).

This is the code that someone posted somewhere which works for white backgrounds:

 

event.target.fillColor = color.white;

if (event.target.buttonImportIcon()!=0) event.target.fillColor = color.transparent;

 

I want that event.target.fillColour to be a specific colour that is not white, but a specific RGB colour value.

Any help or simple way of doing it?

Translate
Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
Jul 31, 2023 7:56 AM UTC

It works when you open the form in Adobe Acrobat or Acrobat Reader.

Translate
Participant
Jul 31, 2023 12:04 PM UTC

I realised I made a mistake, forgot the basics... forgot the capitilisation in the lookup.

Translate