OK, so I’ve created an onChange event handler for my page and connected it to a dropdown. When a user selects an item from the dropdown, an image next to the dropdown is supposed to change based on their selection. The problem is that the image maintains its default and I get the following error in the console:
Wix code SDK error: The src parameter that is passed to the src method cannot be set to the value [object Object]. It must be of type string.
Here’s the code for the onChange event; the bottom section in bold italics specifically:
export function dropdown1_change(event, $w) {
let selectedSchool = $w(‘#dropdown1’).value;
wixData.query(“2020_Registration”)
.find()
.then( (results) => {
studentData = results.items;
const dropdownFilter = studentData.filter( function (dropdown) {
return dropdown.status === “Student” && dropdown.schoolName === selectedSchool;
})
console.log(dropdownFilter)
$w(‘#repeater1’).data = dropdownFilter;
})
. catch ( (err) => {
let errorMsg = err
})
wixData.query(“schoolCrests”)
.find()
.then( (res) => {
crestData = res.items;
const dropdownFilterCrests = crestData.filter(function(dropdownCrests) {
return dropdownCrests.schoolName === selectedSchool;
})
console.log(dropdownFilterCrests);
if(dropdownFilterCrests === null || dropdownFilterCrests === undefined) {
$w(‘#image4’).src = “https://static.wixstatic.com/media/aa2f46_b4aaf1740f9a47ee8c801c135f9524e0~mv2.jpg”;
}
else{
$w(‘#image4’).src = dropdownFilterCrests
}
})
}
Interestingly, the first part of the above code sets the data for a repeater which contains an image that loads properly without error. Also, on page load I use the below code for the same image4 and get no problems and no errors:
$w.onReady(function() {
wixData.query(“schoolCrests”)
.find()
.then( (res) => {
crestData = res.items;
if (crestData.crest === null || crestData.crest === undefined) {
$w(‘#image4’).src = “https://static.wixstatic.com/media/aa2f46_b4aaf1740f9a47ee8c801c135f9524e0~mv2.jpg”;
}
else {
$w(‘#image4’).src = crestData.crest;
}
console.log(“loaded school crest to associated image”);
})
. catch ( (err) => {
let errorMsg = err
})
})
Any ideas?