XF 2.2 on/off checkbox with textbox

Old Nick

Well-known member
This is my settings :

ID : gmValue
Format parameters :
Code:
onoff=enabled
value=limit
min=0
default=0
type=spinbox
step=10
Data type : array
Default value : {"enabled":"0","limit":"0"}
Array sub-options :
Code:
enable
limit

So if I check the box to activate the numeric field and I enter 20 as the value how to use this value 20 in a template?
With a classic field I know the syntax :
Code:
{$user.trophy_points|number} >= '$xf.options.gmValue'
But as I have defined an array how can I get out of it? Should I first say that the box is checked and then put the value? What's the syntax for that?
Thank you for your help.
 
It should just be like so: $user.trophy_points >= $xf.options.gmValue.limit

The number filter probably isn't what you want there, as it's a number format function, not something that is casting to a number. For example if you had a situation where trophy_points was 10000, the number filter is turning it into a string as 10,000 (adding comma separator). So using that starts to become problematic with the comparison operator if it's greater than 999.
 
It's interesting.
So what would be the right way to display content under the condition of a value greater than X knowing that this value will quickly exceed 999?
Is |raw can be used in this case?

Or should we use string rather than number, is that what you're telling me?
Thank you.
 
That would be the right way to display the data, but not for comparison operators. For display:

{$user.trophy_points|number}

For comparison:

<xf:if is="$user.trophy_points >= $xf.options.gmValue.limit">...</xf:if>
 
<xf:if is="$user.trophy_points >= $xf.options.gmValue.limit">...</xf:if>
Ah, I understand your remark better now, and it's my fault I misled you: it is indeed as you have just written it, in the form of a condition, that I use it but I had omitted to specify it and above all I had taken $user.trophy_points >= $xf.options.gmValue.limit out of its context <xf:if is="">...</xf:if>.

I thought using the on/off checkbox with textbox it changed the syntax to use in HTML, implying there was a value for the on/off and a value for the field. That's clear now, thank you @digitalpoint.
 
Back
Top Bottom