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

Custom validation script help

New Here ,
Dec 05, 2022 Dec 05, 2022

Copy link to clipboard

Copied

I am attempting to use a custom validation script in a drop down field to set the field fill colour once committed. I have selected to commit the value immediately and the code works in principle. But, half of the colours are giving the wrong result. The code is below. The notes after each line are not actually within my code I added them to demonstrate the issue:

 

if(/\A1/.test(event.value))event.target.fillColor = ["RGB",0/255,255/255,255/255]; //blue

else if(/\A2/.test(event.value))event.target.fillColor = ["RGB",0/255,255/255,255/255]; //blue

else if(/\A3/.test(event.value))event.target.fillColor = ["RGB",0/255,255/255,255/255]; //blue

else if(/\B1/.test(event.value))event.target.fillColor = ["RGB",0/255,255/255,255/255]; //blue

else if(/\B2/.test(event.value))event.target.fillColor = ["RGB",0/255,255/255,255/255]; //blue

else if(/\C1/.test(event.value))event.target.fillColor = ["RGB",0/255,255/255,255/255]; //blue

else if(/\A4/.test(event.value))event.target.fillColor = ["RGB",0/255,255/255,0/255]; //green

else if(/\A5/.test(event.value))event.target.fillColor = ["RGB",0/255,255/255,0/255]; //green

else if(/\B3/.test(event.value))event.target.fillColor = ["RGB",0/255,255/255,0/255]; //green

else if(/\C2/.test(event.value))event.target.fillColor = ["RGB",0/255,255/255,0/255]; //blue – Should be green

else if(/\D1/.test(event.value))event.target.fillColor = ["RGB",0/255,255/255,0/255]; //green

else if(/\E1/.test(event.value))event.target.fillColor = ["RGB",0/255,255/255,0/255]; //blue – Should be green

else if(/\B4/.test(event.value))event.target.fillColor = ["RGB",255/255,255/255,0/255]; //yellow

else if(/\B5/.test(event.value))event.target.fillColor = ["RGB",255/255,255/255,0/255]; //yellow

else if(/\C3/.test(event.value))event.target.fillColor = ["RGB",255/255,255/255,0/255]; //green – Should be yellow

else if(/\D2/.test(event.value))event.target.fillColor = ["RGB",255/255,255/255,0/255]; //cyan – Should be yellow

else if(/\E2/.test(event.value))event.target.fillColor = ["RGB",255/255,255/255,0/255]; //cyan – Should be yellow

else if(/\C4/.test(event.value))event.target.fillColor = ["RGB",255/255,128/255,0/255]; //yellow – Should be orange

else if(/\C5/.test(event.value))event.target.fillColor = ["RGB",255/255,128/255,0/255]; //yellow – Should be orange

else if(/\D3/.test(event.value))event.target.fillColor = ["RGB",255/255,128/255,0/255]; //green – Should be orange

else if(/\D4/.test(event.value))event.target.fillColor = ["RGB",255/255,128/255,0/255]; //yellow – Should be orange

else if(/\E3/.test(event.value))event.target.fillColor = ["RGB",255/255,128/255,0/255]; //green – Should be orange

else if(/\D5/.test(event.value))event.target.fillColor = ["RGB",255/255,0/255,0/255]; //yellow – Should be red

else if(/\E4/.test(event.value))event.target.fillColor = ["RGB",255/255,0/255,0/255]; // yellow – Should be red

else if(/\E5/.test(event.value))event.target.fillColor = ["RGB",255/255,0/255,0/255]; // yellow – Should be red

else event.target.fillColor = ["RGB",255/255,255/255,255/255]; //white

 

I should note, I adapted this code from multiple different threads within this forum, so I am completely unsure what the problem is, but from my limited experience I am assuming it may be something to do with the logic parameters as I don't really understand what the forward and back slashes are doing or it may be a limitation on the program itself.

 

Any help will be thoroughly appreciated.

TOPICS
Create PDFs , Edit and convert PDFs , General troubleshooting , How to , JavaScript , PDF forms

Views

1.4K

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Dec 05, 2022 Dec 05, 2022

Do you actually test dropdown choices or are those actual values of dropdown?

If you test them use this:

if(/A1|A2|A3|B1|B2|C1/g.test(event.value))event.target.fillColor = ["RGB",0/255,255/255,255/255]; //blue
else if(/A4|A5|B3|C2|D1|E1/g.test(event.value))event.target.fillColor = ["RGB",0/255,255/255,0/255]; //green
else if(/B4|B5|C3|D2|E2/g.test(event.value))event.target.fillColor = ["RGB",255/255,255/255,0/255]; //yellow
else if(/C4|C5|D3|D4|E3/g.test(event.value))event.target.fillColor = ["RGB"

...

Votes

Translate

Translate
Community Expert ,
Dec 05, 2022 Dec 05, 2022

Copy link to clipboard

Copied

Do you actually test dropdown choices or are those actual values of dropdown?

If you test them use this:

if(/A1|A2|A3|B1|B2|C1/g.test(event.value))event.target.fillColor = ["RGB",0/255,255/255,255/255]; //blue
else if(/A4|A5|B3|C2|D1|E1/g.test(event.value))event.target.fillColor = ["RGB",0/255,255/255,0/255]; //green
else if(/B4|B5|C3|D2|E2/g.test(event.value))event.target.fillColor = ["RGB",255/255,255/255,0/255]; //yellow
else if(/C4|C5|D3|D4|E3/g.test(event.value))event.target.fillColor = ["RGB",255/255,128/255,0/255]; //orange
else if(/D5|E4|E5/g.test(event.value))event.target.fillColor = ["RGB",255/255,0/255,0/255]; //red
else event.target.fillColor = ["RGB",255/255,255/255,255/255]; //white

 

If those are actual values, you can also use this:

switch(event.value){
case "A1":
case "A2":
case "A3":
case "B1":
case "B2":
case "C1":
event.target.fillColor = ["RGB",0/255,255/255,255/255]; //blue
break;
case "A4":
case "A5":
case "B3":
case "C2":
case "D1":
case "E1":
event.target.fillColor = ["RGB",0/255,255/255,0/255]; //green
break;
case "B4":
case "B5":
case "C3":
case "D2":
case "E2":
event.target.fillColor = ["RGB",255/255,255/255,0/255]; //yellow
break;
case "C4":
case "C5":
case "D3":
case "D4":
case "E3":
event.target.fillColor = ["RGB",255/255,128/255,0/255]; //orange
break;
case "D5":
case "E4":
case "E5":
event.target.fillColor = ["RGB",255/255,0/255,0/255]; //red
break;
default:
event.target.fillColor = color.white;}

 

Votes

Translate

Translate

Report

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 ,
Dec 05, 2022 Dec 05, 2022

Copy link to clipboard

Copied

@Nesa Nurani 

 

I thought the same thing.

 

I am not sure why is the OP treating the event value as a regular expression that needs to be tested.

 

I believe is completely unnecessary as you've observed, but it actually worked pretty good when I tested it as is.

 

This can also be easily done with a custom format script or even with a custom  keystroke script which:

https://stackoverflow.com/questions/52042730/conditional-formatting-color-fill-in-adobe-acrobat-dc

Votes

Translate

Translate

Report

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 ,
Dec 05, 2022 Dec 05, 2022

Copy link to clipboard

Copied

LATEST

Works perfectly thanks, for this and all other replies. Thanks for your assistance, and for clarification the reasoning behind the bad coding is I have no idea what I'm doing - novice.

Votes

Translate

Translate

Report

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 ,
Dec 05, 2022 Dec 05, 2022

Copy link to clipboard

Copied

You shouldn't divide the bit octects inside of the color array object operation  like that or it will throw erratic results.

 

Do the division of the RGB channel on a calculator and then test the desired result like this:

 

 

+++++EDITE REPLY , was missing variable f declared in the script

 

var f = event.target;

if(/\A4/.test(event.value)) f.fillColor = ["RGB",1,0,1];  // for LIGHT PURPLE
else if(/\A5/.test(event.value)) f.fillColor = ["RGB",1,0.5,0];  // for ORANGE
else if(/\B1/.test(event.value)) f.fillColor = ["RGB",0,0,1];  // for blue
else if(/\B2/.test(event.value)) f.fillColor = ["RGB",1,0,0];  // for red
else if(/\B3/.test(event.value)) f.fillColor = ["RGB",0,1,0];  // for green
else if(/\B4/.test(event.value)) f.fillColor = ["G",1];  // for white
else if(/\B5/.test(event.value)) f.fillColor = ["RGB",1,1,0];  // for yellow

 

 

See  additional tips and  guidance below  from the Adobe Commnity Pros:

 

 

Votes

Translate

Translate

Report

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 ,
Dec 05, 2022 Dec 05, 2022

Copy link to clipboard

Copied

What entries does you use at the dropdown?

Votes

Translate

Translate

Report

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