@ajithkrr The code is more complex than that.
In all there are 2 repeaters and I should be able to click the button on the first repeater and add that element in the second by deactivating the button and when I remove it from the second the button of the first is reactivated
let secondRepeaterData = [];
let itemShop = {};
var testoMostrato;
var daRimuovere = [];
var boxId;
function buildBox() {
$w("#repeater1").onItemReady(($item, itemData, index) => {
$item("#btnAdd").onClick((event) => {
console.log('clicked');
boxId = index;
console.log(boxId);
let productName = $item('#txtProductName').text;
let productPrice = $item('#txtProductPrice').text;
let priceValue = parseInt($item('#txtProductPrice').text, 10);
console.log(priceValue);
itemShop = {
"_id": productName,
"nome": productName,
"prezzo": productPrice,
"prezzoNumero": priceValue
};
secondRepeaterData.push(Object.assign({}, itemShop));
console.log(secondRepeaterData);
$w("#repeater2").data = secondRepeaterData;
$w("#repeater2").onItemReady(($itemRepeater, itemData1, index) => {
$itemRepeater("#txtName").text = itemData1.nome;
$itemRepeater("#txtPrice").text = itemData1.prezzo;
console.log(itemData1)
// update budget
console.log(secondRepeaterData)
var price = secondRepeaterData.reduce(function (prev, cur) {
return prev + cur.prezzoNumero;
}, 0);
testoMostrato = budgetScelto - price;
$w('#txtBudget').text = testoMostrato.toString();
console.log(price)
//show second repeater and disable button
$w('#repeater2').expand();
$item('#btnAdd').disable();
})
});
});
$w("#repeater2").onItemReady(($item, itemData, index) => {
$item("#btnRemove").onClick((event) => {
//riattiva pulsante
daRimuovere.push(boxId);
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;
});
}