fillcolor boolean discrepancy

Participant ,
Jan 29, 2018

Copy link to clipboard

Copied

Hey everyone,

Could someone explain the below (console) behavior for me? ( Nb. f1. is a text field that is gray.)

f1.fillColor==color.gray

false

f1.fillColor

G,0.5

color.gray

G,0.5

I'd like to use the background color for booleans , but because the top comparison fails I'm at a loss.

For this particular instance I have a workaround but for my overall understanding I'd be happy to know why this works this way

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Color objects are actually an array, and arrays can't be compared to each other directly in JS.

So this code will return false:

[1]  == [1]

The solution is to use the built-in equal method of the color object.

For example, this will return true:

color.equal(color.red, ["RGB", 1, 0, 0])

TOPICS
Acrobat SDK and JavaScript, Windows

Views

157

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

fillcolor boolean discrepancy

Participant ,
Jan 29, 2018

Copy link to clipboard

Copied

Hey everyone,

Could someone explain the below (console) behavior for me? ( Nb. f1. is a text field that is gray.)

f1.fillColor==color.gray

false

f1.fillColor

G,0.5

color.gray

G,0.5

I'd like to use the background color for booleans , but because the top comparison fails I'm at a loss.

For this particular instance I have a workaround but for my overall understanding I'd be happy to know why this works this way

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Color objects are actually an array, and arrays can't be compared to each other directly in JS.

So this code will return false:

[1]  == [1]

The solution is to use the built-in equal method of the color object.

For example, this will return true:

color.equal(color.red, ["RGB", 1, 0, 0])

TOPICS
Acrobat SDK and JavaScript, Windows

Views

158

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
Jan 29, 2018 0
Most Valuable Participant ,
Jan 29, 2018

Copy link to clipboard

Copied

Color objects are actually an array, and arrays can't be compared to each other directly in JS.

So this code will return false:

[1]  == [1]

The solution is to use the built-in equal method of the color object.

For example, this will return true:

color.equal(color.red, ["RGB", 1, 0, 0])

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...
Jan 29, 2018 1
Adobe Community Professional ,
Jan 29, 2018

Copy link to clipboard

Copied

You can use this:

f1.fillColor.join('|') == color.gray.join('|')

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...
Jan 29, 2018 0
Most Valuable Participant ,
Jan 29, 2018

Copy link to clipboard

Copied

Why would you want to do that if you have a perfectly good built-in comparison method, that even converts the two values to the same color-space, if needed?
For example, this returns true:

color.equal(["RGB",1,1,0], ["CMYK",0,0,1,0])

This returns false:

["RGB",1,1,0].join('|') == ["CMYK",0,0,1,0].join('|')

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...
Jan 29, 2018 2
Adobe Community Professional ,
Jan 29, 2018

Copy link to clipboard

Copied

I have only found the join solution.

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...
Jan 29, 2018 1
Participant ,
Feb 05, 2018

Copy link to clipboard

Copied

Thank you, good to know!

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...
Feb 05, 2018 0