I’m trying to use .inRange in a class toggle.
This works
<td dmx-text="qty_250" dmx-class:green="qty_250>200"></td>
This doesn’t
<td dmx-text="qty_250" dmx-class:green="qty_250.inRange(200, 300)"></td>
Am I doing something wrong?
Thanks.
I’m trying to use .inRange in a class toggle.
This works
<td dmx-text="qty_250" dmx-class:green="qty_250>200"></td>
This doesn’t
<td dmx-text="qty_250" dmx-class:green="qty_250.inRange(200, 300)"></td>
Am I doing something wrong?
Thanks.
Is this expression used in the table cell rendering true or false then?
{{qty_250.inRange(200, 300)}}
Sorry Teodor, not sure what you mean. I thought using inRange would return true if the value is in that range and false if not?
It’s setup like this…
Just use this expression: {{qty_250.inRange(200, 300)}}
to output the value on the page and see if it returns true or if it returns false for this exact record!
Ah, sorry. I see what you mean now. It’s actually not returning anything.
So what value does the {{qty_250}}
return exactly? Is it a string or a number?
Do you see errors in the browser console?
It’s in a repeat table so it returns a range of values. The first column in the image below is set to return the true/false. The second column is set to the qty_250 field.
<td class="text-dark">{{qty_250.inRange(200,300}}</td>
<td dmx-text="qty_250" dmx-class:green="qty_250.inRange(200,300)"></td>
No errors in the console.
So when you open the XHR tab in the dev tools of your browser and see the values returned- are they strings or numbers? Please post a screenshot.
Ha ha! Right you were…
Adding toNumber() works.
qty_250.toNumber().inRange(200,300)
However, is there a reason this is being output as text when the schema for the query is specifically set to number?
Depends on your database driver. What’s your database type and what server model are you using?
MySQL/PHP
What version of PHP and what version of mysql are you using? There are known issues with specific older versions of mysql in php prior version 7, where the driver returns integers as strings.
7.4
If I re-run the Query it changes all the data types to Text, even the one cast to an integer.
Changing those to number doesn’t fix the issue.
I’ve double checked that they are Int fields in the database and even tried changing to a few other number types but the issue persists.
In my other projects I haven’t had a huge need for numbers but recall running up against this a while ago and IIRC just used the .toNumber() to solve the issue.
Curious, I checked db queries in all of my projects (multiple databases and domains but all on the same server) and all return strings for numbers. I tried changing the PHP version to 8 and did a bit of Googling but so far no result.
It’s honestly not a huge issue for me as I can just add the .toNumber() on the client side but it would be good to figure out I think. Perhaps if the user changes the Type in the Schema .toNumber() could be added on the server side backend?