I have a code that allows you to transfer information from a first repeater to a second by deactivating the button (and so far so good) But it should also allow you to remove the information from the second dataset by reactivating the first button. (removal works but the button is not reactivated)
The problematic code I think is this:
$w("#repeater2").onItemReady(($item, itemData, index) => {
$item("#btnRemove").onClick((event) => {
//riattiva pulsante
console.log('Index 2 = '+ index)
daRimuovere.push(index);
console.log(daRimuovere);
enableButton()
// elimina dal dataset
secondRepeaterData = secondRepeaterData.filter(object => object._id !== itemData._id);
$w("#repeater2").data = secondRepeaterData;
console.log(secondRepeaterData);
// update budget
var price = secondRepeaterData.reduce(function (prev, cur) {
return prev + cur.prezzoNumero;
}, 0);
testoMostrato = budgetScelto - price;
$w('#txtBudget').text = testoMostrato.toString();
console.log(testoMostrato.toString())
});
});
}
function enableButton() {
$w("#repeater1").forItems(daRimuovere, ($item, itemData, index) => {
$item('#btnAdd').enable;
});
}
And so it returns me this error:
It seems that the onItemReady() command does not recognize the id, which however is present because in the first part of the code I take the id through the index:
$w("#repeater1").onItemReady(($item, itemData, index) => {
$item("#btnAdd").onClick((event) => {
console.log(index);
let ID1 = index.toString();
let productName = $item('#txtProductName').text;
let productPrice = $item('#txtProductPrice').text;
let priceValue = parseInt($item('#txtProductPrice').text, 10);
console.log(priceValue);
itemShop = {
"_id": ID1,
"nome": productName,
"prezzo": productPrice,
"prezzoNumero": priceValue
};
This is not the complete function but only one piece