Load repeater using code from local array using an event listener outside of the repeater

Discussion:
Wix Velo Code:
I want to load a repeater without connecting to the collection/dataset. Repeater Id $w(“#selectedMedicineRepeater1”)

What are you trying to achieve:
I have 2 text input fields and a dropdown outside of the repeater. I have a button outside of the repeater.

Input field ids:
$w(“#searchDrugInput”)
$w(“#quantityInput1”)

Dropdown Id:
$w(“#typeOfUnitDropdown”)

Button Id:
$w(“submitRequisitionButton”)

I can insert the values from the input fields and dropdown using the event listeners into array of the repeater by decalring a local array. But I can’t load the repeater on my page after inserting the values into the array.

I am not sure whether what javascript array method I should be using to display the itemData on my page.

Please could somebody help

Are you able to share the code you currently have?

Hey Noah,

I wasn’t sure about which javascript array method I should be using. I am a novice in coding. Thanks for asking about it. The code I have currently written is below:

$w.onReady(function () {

const exampleData = [
{“_id”: “1”, “medicine”: “Medicine Name1”, “unit”: “Type of Unit1”, “quantity”: “Quantity of Medicine1”},
{“_id”: “2”, “medicine”: “Medicine Name2”, “unit”: “Type of Unit2”, “quantity”: “Quantity of Medicine2”},
{“_id”: “3”, “medicine”: “Medicine Name3”, “unit”: “Type of Unit3”, “quantity”: “Quantity of Medicine3”},
{“_id”: “4”, “medicine”: “Medicine Name4”, “unit”: “Type of Unit4”, “quantity”: “Quantity of Medicine4”},
{“_id”: “5”, “medicine”: “Medicine Name5”, “unit”: “Type of Unit5”, “quantity”: “Quantity of Medicine5”},
{“_id”: “6”, “medicine”: “Medicine Name6”, “unit”: “Type of Unit6”, “quantity”: “Quantity of Medicine6”},
{“_id”: “7”, “medicine”: “Medicine Name7”, “unit”: “Type of Unit7”, “quantity”: “Quantity of Medicine7”},
{“_id”: “8”, “medicine”: “Medicine Name8”, “unit”: “Type of Unit8”, “quantity”: “Quantity of Medicine8”}
];

console.log(exampleData.length);
console.log(exampleData);

let added = 0;

$w(“#selectedMedicineRepeater1”).data = ;

$w(“#selectedMedicineRepeater1”).onItemReady(($item, itemData, index)=>{
$item(“#displayMedicineNameText”).text = itemData.medicine;
$item(“#displayTypeOfUnitText1”).text = itemData.unit;
$item(“#displayQuantityText1”).text = itemData.quantity;
})

$w(“#typeOfUnitDropdown”).onChange((event)=>{
console.log($w(“#typeOfUnitDropdown”).value + " " + “was selected”);
$w(“#selectedMedicineRepeater1”).onItemReady(($item, itemData, index)=>{
exampleData[index].unit = event.target.value; // Update the title in the corresponding object
$w(“#selectedMedicineRepeater1”).data = exampleData; // Update the repeater data
console.log(event.target.value);
})

})

$w(“#submitRequisitionButton”).onClick(()=>{
$w(“#selectedMedicineRepeater1”).data= exampleData.splice(0, ++added);
})

});

Sorry Noah I made a typo while copying and pasting.

after

let added = 0;

the i declared and emptry array for repeater $w(“#selectedMedicineRepeater1”).data