Cookie value won't increment

Wappler Version : 4.2.0
Operating System : Windows 10 x64 21H1
Server Model: NodeJS
Database Type: PostgreSQL
Hosting Type: Docker

Expected behavior

Cookie value increment by one.

Actual behavior

I have cookie set as Number type and I want to increment it’s value by 1.
If I set cookie without toNumber() it just add +1 to value as a string - it becomes 1, 11, 111 etc.
If I set cookie with toNumber() on first attempt cookie sets to 1, on second - it shows error:
parser.js:798 Formatter toNumber in expression [cookies.set('random_number',cookies.data.random_number.toNumber() + 1,{})] doesn't exist for type string

How to reproduce

  1. Create cookie as a number type
  2. Add action to add to current cookie +1

Where and how are you creating/setting the cookie?

In layout page via Cookie manager.

I’ve already tried to delete and create - same results.

Works perfectly fine in my test:

dmx-on:click="cookies1.set('mycookie',cookies1.data.mycookie.toNumber() + 1,{})"

Maybe check if the formatter js file is not missing from your layout page and that is saved also.

Indeed, looks like formatter.js is missing. What would be a proper way to add it?

When you format an expression using the data picker it will be added automatically.

1 Like

After formatter.js was added - everything worked as expected with .toNumber()
Thank you.