Hello everyone!
I want to accomplish having a list of items in my repeater, each with a button labeled “Mark as Completed” and if clicked, it should update a field in the dataset (set to true).
So far I only have accomplished displaying a certain text for each repeater item if the dataset field is equal to true.
export function dataset1_ready() {
completed()
}
export function completed() {
$w('#repeater1').forEachItem(($item, itemData, index) => {
if (itemData.completed === true) {
$item('#text10').show()
}
})
}
Now I need a function that enables the user to click the button “Mark as completed” and set itemData.completed to true for the current repeater item
Absolutely the same way you do it outside of REPEATER, with the only difference…----> using —> $item for Elements inside REPEATER.
export function dataset1_ready() {
completed()
}
export function completed() {
$w('#repeater1').forEachItem(($item, itemData, index) => {
if (itemData.completed === true) {
$item('#text10').show()
$item("#ELEMENT_ID").onClick( (event) => {xxx()});
}
})
}
function xxx(){
...here your CODE...
}
for example…
function xxx(){
wixData.query("DATACOLLECTION").eq('REFERENCE', "VALUE")
.find()
.then(results => {
console.log(results)
});
}
Thanks! now I’m having trouble with the xxx() which i’ve named markCompleted()
export function dataset1_ready() {
completed()
markCompleted()
}
export function completed() {
$w('#repeater1').forEachItem(($item, itemData, index) => {
if (itemData.completed === true) {
$item('#text10').show()
$item("#button1").onClick((event) => { markCompleted()() });
}
})
}
export function markCompleted() {
wixData.query("WORKOUTS")
.find()
.then((results) => {
results.completed = true;
wixData.update("WORKOUTS", results)
})
}
Not working… here’s how my DB looks
@santiagogc182
How to work with DATA and DATABASES and how to get data out of them, please take a look here in this post, where i have explained it more detailed…
Link: