Formatter doesn't exist for type number

Hey all,

Quick one:

I’ getting an error when I try to use a formatter, looking up a number and replacing with text. This is the ‘warning’ in the console - which accumulates to 100’s and 100’s of warnings on the same page as I scroll (repeat group):

dmxAppConnect.js:7 Formatter replace in expression [require_sponsorship.replace(1, ‘Yes’).replace(0, ‘No’)] doesn’t exist for type number

Here is what I have in the data binder:
Screen Shot 2020-09-18 at 12.17.19 pm

Clearly doing something wrong here! Can anyone point me in the right direction? Is it not possible to replace a number with text, for example and I need to look for alternatives?

I believe replace is entirely for strings – probably need to quote the 1 and 0 by converting to string

Sorry, that was really vague.

If require_sponsorship is a numeric value, then maybe try:

require_sponsorship.toString().replace('1','Yes').replace('0', 'No')

Thank you Ken, I didn’t realise replace was only for strings. The field is actually boolean, but as I understand it depending on how it’s used within Wappler is either a 0 and 1, (which works well in some cases) or true, false. I can’t seem to convert to string - but will continue to try different solutions.

Then you probably want to use a ternary.

ternary frighten me. Ok, time to learn some more. Thanks Ken.

require_sponsorship ? 'Yes' : 'No'

Not scary, just something new. :slight_smile: