How can I store the selected item into a variable from the event? I mean I want to use that variable inside my Tulip app
If you look at the screenshot, It says that the event has been fired, but I’m not able to catch the value in tulip player
The intention of this, is to create a button from each row from an array and then select the desired value
This is the code I used in Javascript:
let selectedItem = null;
const widgetContainer = document.getElementById(“widgetContainer”);
function fireEvent(eventName, eventData) {
console.log(“Evento disparado:”, eventName, “Datos:”, eventData);
const event = new CustomEvent(eventName, { detail: eventData });
document.dispatchEvent(event);
}
let dataArray = ;
const handlePropChange = (newValue) => {
dataArray = newValue.map((item) => {
const [
Location,
PartNumber,
LotSerial,
Reference,
QOH,
Site,
Expirationdate,
] = item.split(“,”);
return {
Location,
partNumber: PartNumber,
LotSerial,
Reference,
QOH,
Site,
Expirationdate,
};
});
updateUI();
};
const updateUI = () => {
widgetContainer.innerHTML = “”;
dataArray.forEach((item, index) => {
const element = document.createElement(“div”);
element.className = “item”;
const button = document.createElement("button");
button.innerText = `Select`;
button.className = "button";
button.onclick = () => {
selectedPart(item);
};
element.appendChild(button);
const info = document.createElement("div");
info.innerHTML = `
<strong>Part Number:</strong> ${item.partNumber}<br>
<strong>Location:</strong> ${item.Location}<br>
<strong>Quantity on Hand:</strong> ${item.QOH}<br>
<strong>Lot Serial:</strong> ${item.LotSerial}<br>
<strong>Reference:</strong> ${item.Reference}<br>
<strong>Expiration Date:</strong> ${item.Expirationdate}
`;
element.appendChild(info);
widgetContainer.appendChild(element);
});
};
function selectedPart(part) {
selectedItem = part;
const selectedItemText = JSON.stringify(selectedItem);
fireEvent(“itemSelected”, { selectedItem: selectedItemText });
}
getValue(“DataArray”, handlePropChange);