Hi, everyone.
I'm trying to make an image dynamically change an image according to the item selected in the selector right below it. Did the most logical thing I could think of adding a function to 'on change' selector event. But it didn't seem to work. I must be doing something wrong but can't seem to figure what.
Here is the function that is executed on change of the selector status.
// Create a function to handle the onChange event of the 'asset_type' selector
function handleAssetTypeChange(value) {
const coverImage = cover_image; // Assuming 'cover_image' is the ID of the RNImageWidget for the cover image
// Define an object that maps the asset type options to their corresponding image URLs
const assetTypeToImageUrl = {
"Jaibot Hydro": "https://www.jaia.tech/wp-content/uploads/2023/02/Rocket_3-scaled.jpg",
"ASV Maco": "https://www.fieldwerx.com/wp-content/uploads/2023/08/DSC8412.jpg",
"Stationary Buoy": "https://www.fieldwerx.com/wp-content/uploads/2023/05/DSC5320-1.jpg",
"ASV Mascat": "https://www.fieldwerx.com/wp-content/uploads/2022/10/DSC2551.jpg",
"ASV BlueBoat": "https://www.fieldwerx.com/wp-content/uploads/2023/04/BR-101447-1-1-900x900-1.jpeg",
"Weather Station": "https://www.fieldwerx.com/wp-content/uploads/2023/05/telecom-towers-and-digital-and-analog-television-t-2021-10-21-02-23-11-utc-scaled.jpg",
};
// Update the cover image source based on the selected asset type value
const imageUrl = assetTypeToImageUrl[value] || "https://www.fieldwerx.com/wp-content/uploads/2022/10/DSC2551.jpg";
coverImage.setSource(imageUrl);
}
// Assuming 'asset_type' is the ID of the RNSelectWidget for the asset_type selector
asset_type.onValueChanged((value) => {
handleAssetTypeChange(value);
});
// Initialize the cover image with the default image URL
handleAssetTypeChange(asset_type.value);