I have a repeater with toggle buttons which allow the user to show or hide their item(s) on their menu. The problem is that on “preview” the code works flawlessly, but in “live”, unreliable. Sometimes it works, and sometimes does not. I’ve already checked the live DB permissions (anyone), tried timeouts, and nothing. Also, tried to do a query after save but nothing either. Could someone help please?
import wixData from ‘wix-data’ ;
let switchButtonVal = false ;
$w.onReady( function () {
});
$w.onReady( async () => { //Menu repeater
const buttonRepeater = $w( “#menuRepeater” );
buttonRepeater.onItemReady(($w, itemData, index) => {
$w( "#showHideBtn" ).onClick((event) => { //Add button on each menu item
if ($w( “#showHideBtn” ).checked) {
switchButtonVal = true ;
} else {
switchButtonVal = false ;
}
let itemID = $w( “#partnerDataset” ).getCurrentItem()._id;
let cat = $w( “#partnerDataset” ).getCurrentItem().category;
let itemName = $w( “#partnerDataset” ).getCurrentItem().dishName;
let desc = $w( “#partnerDataset” ).getCurrentItem().description;
let price = $w( “#partnerDataset” ).getCurrentItem().price;
let pic = $w( “#partnerDataset” ).getCurrentItem().picture;
let catNum = $w( “#partnerDataset” ).getCurrentItem().categoryNumber;
let toUpdate = {
“_id” : itemID,
“category” : cat,
“dishName” : itemName,
“description” : desc,
“price” : price,
“picture” : pic,
“categoryNumber” : catNum,
“showHide” : switchButtonVal
};
//console.log("line 43: index: " + index);
wixData.save( “TerraventoDB” , toUpdate)
.then( (results) => {
let valueChecked = showHideDoubleCheck(itemID, index)
} )
. catch ( (err) => {
let errorMsg = err;
} );
});
});
});
function showHideDoubleCheck(itemID, index, valueChecked) {
wixData.query( “TerraventoDB” )
.eq( “_id” , itemID)
.find()
.then( (doubleCheckResult) => {
valueChecked = doubleCheckResult.items[index].showHide;
return valueChecked;
} )
. **catch** ( (err) => {
let errorMsg = err;
} );
return valueChecked;
}