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

Formatting code for forms - allowing for mistakes

New Here ,
Jul 30, 2023 Jul 30, 2023

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!

TOPICS
JavaScript , PDF , PDF forms
1.1K
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
1 ACCEPTED SOLUTION
Community Expert ,
Jul 31, 2023 Jul 31, 2023

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

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 ,
Jul 31, 2023 Jul 31, 2023

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

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
New Here ,
Jul 31, 2023 Jul 31, 2023

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

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
New Here ,
Aug 22, 2024 Aug 22, 2024

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
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 ,
Aug 22, 2024 Aug 22, 2024

You can always describe what you need so we can help 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
New Here ,
Sep 02, 2024 Sep 02, 2024
LATEST

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
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