I am creating a website with a summary container box. On the container box, I would like to summarize a customer order according to the service they wanted.
One of the inputs is selection tags that connect to a repeater, showing name and price.
Now, When I try to add the value of the repeater using the code below, it doubles or triple the price of the item
function setRepeatedItemsInRepeater() {
var tagConcat;
const selectedTags = $w( ‘#selectionTags1’ ).value;
let nr = selectedTags.length;
let sum = 0 ;
$w( ‘#repeater1’ ).onItemReady(($item, itemData) => {
$item( ‘#extraSvcTitle’ ).text = itemData.shortName;
$item( ‘#extraCSvcPrice’ ).text = String(parseFloat(itemData.price).toFixed( 2 ));
for ( var i = 0 ; i <= nr; i ++) {
sum += parseFloat(itemData.price);
$w( '#text190' ).text = String(sum); // here is the big text file in the screenshot
}
})
}
let dataQuery = wixData.query(collectionName);
if (selectedCategories.length > 0 ) {
dataQuery = dataQuery.hasSome(fieldToFilterByInCollection,selectedCategories);
}
dataQuery
.find()
.then(results => {
// const cnt = results.totalCount;
const itemsReadyForRepeater = results.items;
$w( ‘#repeater1’ ).data = itemsReadyForRepeater;
const isRepeaterEmpty = itemsReadyForRepeater.length === 0
// $w(‘#text191’).text = String(cnt);
})
}
$w( ‘#selectionTags1’ ).onChange((event) => {
$w( “#repeater1” ).show();
const selectedTags = $w( ‘#selectionTags1’ ).value;
if (selectedTags.length === 0 ) {
$w( “#repeater1” ).hide();
}
else {
loadDatatoRepeater(selectedTags);
setRepeatedItemsInRepeater(); }
})
});
I concatenated the price in a string and saw that it is indeed double and sometimes tripled (more than) (ignore the undefined it’s just a variable I didn’t define).
Can someone help? Thanks!