Writing a validation script to javascript......

New Here ,
Apr 11, 2018

Copy link to clipboard

Copied

Hi,

I've found a topic about validation of fields.

When a field meet a specific value, the background color changes.

var v = Number(event.value);

if (v>=1 && v<=6) {event.target.fillColor = color.red;}

else event.target.fillColor = color.white;

This is exactly what I want, but I'm using number field with decimals.

How can I check If the value is between 1 and 6.49 and color it red and with all other values, color it white ?

I've tried this, but it didn't work:

var v = Number(event.value);

if (v>=1 && v<=6.49) {event.target.fillColor = color.red;}

else event.target.fillColor = color.white;

Can anyone help me out here ?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Actually, because you formatted the fields as using a comma as the decimal separator, you do have to use it...

In addition, you need to disable the fields highlighting to be able to see the colors.

Go to Edit - Preferences - Forms and tick off "Show border hover color for fields".

TOPICS
Acrobat SDK and JavaScript, Windows

Views

104

Likes

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

Writing a validation script to javascript......

New Here ,
Apr 11, 2018

Copy link to clipboard

Copied

Hi,

I've found a topic about validation of fields.

When a field meet a specific value, the background color changes.

var v = Number(event.value);

if (v>=1 && v<=6) {event.target.fillColor = color.red;}

else event.target.fillColor = color.white;

This is exactly what I want, but I'm using number field with decimals.

How can I check If the value is between 1 and 6.49 and color it red and with all other values, color it white ?

I've tried this, but it didn't work:

var v = Number(event.value);

if (v>=1 && v<=6.49) {event.target.fillColor = color.red;}

else event.target.fillColor = color.white;

Can anyone help me out here ?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Actually, because you formatted the fields as using a comma as the decimal separator, you do have to use it...

In addition, you need to disable the fields highlighting to be able to see the colors.

Go to Edit - Preferences - Forms and tick off "Show border hover color for fields".

TOPICS
Acrobat SDK and JavaScript, Windows

Views

105

Likes

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
Apr 11, 2018 0
Most Valuable Participant ,
Apr 11, 2018

Copy link to clipboard

Copied

Your code is correct and should work. What happens when you change the value of the field?

Keep in mind the script only executes when you exit the field, not the moment you enter the new value.

Likes

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
Reply
Loading...
Apr 11, 2018 0
New Here ,
Apr 11, 2018

Copy link to clipboard

Copied

That's what I thought, but it doesn't work.

When I fill in a whole number (like 1 -6) the background changes to red.

If I fill in 6,4 or 5,2 or 2,2 etc. ect. the background changes to white.

Likes

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
Reply
Loading...
Apr 11, 2018 0
Most Valuable Participant ,
Apr 11, 2018

Copy link to clipboard

Copied

Can you share the file with us (via Dropbox, Google Drive, Adobe Cloud, etc.)?

Likes

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
Reply
Loading...
Apr 11, 2018 0
Most Valuable Participant ,
Apr 11, 2018

Copy link to clipboard

Copied

You have to use a period as the decimal separator, not a comma.

Likes

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
Reply
Loading...
Apr 11, 2018 0
New Here ,
Apr 11, 2018

Copy link to clipboard

Copied

Sorry, that's what I did.

The field is formatted as Number, so I only enter a decimal in the field.

I've uploaded the PDF to Dropbox: Dropbox - Formulier1003.pdf

Please note that this document is in Dutch.

On page 3 I have used the conditional formatting in the 2 columns.

Likes

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
Reply
Loading...
Apr 11, 2018 0
Most Valuable Participant ,
Apr 11, 2018

Copy link to clipboard

Copied

Actually, because you formatted the fields as using a comma as the decimal separator, you do have to use it...

In addition, you need to disable the fields highlighting to be able to see the colors.

Go to Edit - Preferences - Forms and tick off "Show border hover color for fields".

Likes

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
Reply
Loading...
Apr 11, 2018 0
Edwin_S LATEST
New Here ,
Apr 11, 2018

Copy link to clipboard

Copied

try67, your right.

It works fine now.

Thanks for your quick response !!

Likes

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
Reply
Loading...
Apr 11, 2018 0