Hello, I am trying to set up a click counter on a dynamic page.
• In each dynamic page there’s a button #button1 and a dataset #myDataset
• In the dataset there’s a number field named “clicks” and it’s value in the sandbox is 0
• In each dynamic page there’s a text item #text1 connected to the “clicks” field in the database.
Here’s the code I put in my dynamic page:
export function button1_click(event) {
const currentItem = $w("#myDataset").getCurrentItem();
let clickCount = currentItem.clicks + 1;
$w("#myDataset").setFieldValue("clicks",clickCount);
$w('#myDataset').save();
}
This code works fine so when I click the button #button1 , the text inside #text1 shows a number that increases at every click.
The problem here is that when I reload the page, the number inside #text1 resets back to 0.
Can anyone help me fix this issue? Please don’t forward me back to other posts on the forum as I already tried probably everything posted in other posts and I wasn’t able to make this work.
Thanks in advance!