Class toggle and "or" operator

Hello,

I want to apply a class dynamically depending on the variable content.

I am using the Dynamic Attribute and Class Toggle to do that.

This is the code that does not work:

<td dmx-text="version" dmx-class:classname="(version == '2.0') || (version == '3.0')"></td>

I think that the problem is because of the number 0.
If the zeroes are other numbers, it works.

Can you help me, please?

Can you use a different naming convention? Maybe OneZero and TwoZero instead?

No because the values are returned by an API call.

Hmm, I’m wondering if it’s because the 1.0 is being treated as a number so becomes 1. Maybe use a formatter to change it to text?

1 Like

It should be already text, that is why I put the single quotes.

I can’t test this myself at the moment but wonder if it might still need a formatter to change it.

I have just tried to format it to text using the version.toString() function without success.

Shame. Hopefully someone else can chip in with some other thoughts. Sorry I couldn’t solve it.

1 Like

You can confirm this by looking at the results of the api in the dev console of your browser.

As I wrote above, I confirm that the values are text.

image

Might something like this work:
dmx-class:classname="(version.value.toNumber() == 2 ) || (version.value.toNumber() == 3)"
?

2 Likes

I knew converting it was the answer… just got the thinking the wrong way round! :wink:

1 Like