1
votes

I am trying to make a slider from 0-2000, where 2000 displays as "2000+", encapsulating everything >=2000.

My encoder looks like this:

encoder: function(a) {
    a == 2000 ? a = a + '+' : null;
    return a;
}

However, this returns false when a=2000. I take it this is because a needs to be an integer, not a string. How can I conditionally add a postfix, then?

1
Rather than null, and variable assignment, why not: a += a > 2000 ? '+' : ''; ? I suspect, but don't have time to verify, that you're effectively returning null in every non a == 2000 scenario. - David Thomas
it does not work to return an integer with a + suffix. - Nina Scholz
Really, @Nina? I've never had an issue concatenating a string to a number before (when I've deliberately wanted a string as the result). - David Thomas
@NinaScholz Yup, you're right. David Thomas: I believe wnumb is explicitly looking for a number, not a string, so a + '+' returns false. I am specifically asking how to conditionally suffix something inside the wnumb syntax. - j_d

1 Answers

2
votes

Just came across this issue and solved it by using wNumb's edit option.
Not perfect because it checks after all formatting but does the job.

format: wNumb({
    prefix: '$',
    decimals: 0,
    thousand: ',',
    edit: function( value ) {
        return (value == '$2,000') ? '$2,000+' : value;
    }
})