$w(“#button5”) is on a page where a user will click it once they have completed a course. I’m having trouble trying to get the button to save “true” to a boolean field in a collection named “Courses”. I’ve searched for similar issues/read the API reference but can’t figure out why it won’t save. Also for security sake (so users can’t skip the course before submitting), would it be worth having the function run in the events.js file rather than on the front end? Thanks
import wixData from 'wix-data';
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
let user = wixUsers.currentUser;
let userId = user.id;
$w.onReady(function () {
wixData.query("Courses")
.eq("_id", userId)
.find()
.then((results) => {
let toInsert = {
"_id": userId,
"baristaBasics": results.items[0].baristaBasics,
"hospitality101": results.items[0].hospitality101,
"baristaComplete": true,
"hospitalityComplete": results.items[0].hospitalityComplete
//"baristaDate": currentDate
};
$w("#button5").onClick((event) => {
if (results.items[0].baristaComplete !== true) {
wixData.update("Courses", toInsert)
$w("#button5").label = "Changed"
} else {
wixLocation.to('/account/my-courses')
}
})
})
})