Hi everyone,
I'm trying to create a website where only logged-in users can vote for as many items as they want, but only once. It's the same idea as a social media site; you can 'like' whatever you'd like, but only once.
Here's what works:
- Only logged-in users can access the website.
- Once users have clicked the #voteButton, the specific item they 'liked' is incremented by one and the #voteButton is hidden
What I need help with:
- Once a user clicks on any vote button, it increments it by one, but it makes the button disappear for all items rather than the specific item that was clicked --> I want to make it so only the #voteButton on the specific item that was clicked disappears.
- Once an item is clicked, the vote button disappears. However, once the page is reloaded, the vote button appears once again. It's absolutely mandatory for the vote button to be permanently hidden on an item that was already 'liked' or 'voted' in order for users to be able to vote once per item.
- Last but not least, I need all the data on this database to be automatically deleted at the end of each day at midnight.
export function voteButton_click(event) {
let $item = $w.at(event.context);
let currentItem = $item("#dataset1").getCurrentItem();
let currentVotes = Number(currentItem.votes);
$item("#dataset1").setFieldValue("votes",currentVotes + 1);
$item("#dataset1").save();
$w("#voteButton").hide();
}
Thank you for your help and support!
WRONG !!!
$w("#voteButton").hide();
RIGHT !!!
$item("#voteButton").hide();
$w.onReady(async function() {console.log("Dataset ready..."); $w('#dataset1').onReady(()=>{ //What shall happen here??? //You want to be the vote-Button hidden on start when a vote already have been done. //So you will have to code it here when your dataset gets ready... what shall happen ??? // CODE IT... // CODE IT... // CODE IT... // CODE IT... // CODE IT... // CODE IT... // CODE IT... // CODE IT... //Your click-function here ---> only starts when clicking onto your VOTE-BUTTON $w('#voteButton').onClick((event)=>{ let $item = $w.at(event.context); let currentItem = $item("#dataset1").getCurrentItem(); let currentVotes = Number(currentItem.votes); $item("#dataset1").setFieldValue("votes",currentVotes + 1); $item("#dataset1").save(); $item("#voteButton").hide(); }); }); });
You will have to make an if-else-query and code it.
Another idea would maybe be, to generate a further data-field inside of your DATABASE (BOOLEAN-VALUE ---> TRUE/FALSE) and set-up a filter inside of the PROPERTY-PANEL for identification-purposes, but since i do not use the property-panel at all (i code everything i need), so i can't really help here, or i would have to reconstruct your situation to be able to help, this would take a lot of my time.
Back to previous post....