default img if img fails to load

This commit is contained in:
Kara Hoagland 2022-11-21 12:29:06 -08:00
parent 1db54e9f7a
commit 52bc6a27a4
2 changed files with 8 additions and 11 deletions

View File

@ -138,12 +138,11 @@ class ReviewCard extends HTMLElement {
let mealImg = document.createElement("img");
mealImg.setAttribute("id", "a-mealImg");
mealImg.setAttribute("alt","Meal Photo Corrupted");
if(data["mealImg"] != ""){
mealImg.setAttribute("src",data["mealImg"]);
}
else{
mealImg.addEventListener("error", function(e) {
mealImg.setAttribute("src", "./assets/images/icons/plate_with_cutlery.png");
}
e.onerror = null;
});
//meal name setup
let mealLabel = document.createElement("label");

View File

@ -16,12 +16,11 @@ function setupInfo(){
//meal image
let mealImg = document.getElementById("d-mealImg");
if(currReview["mealImg"] != ""){
mealImg.setAttribute("src",currReview["mealImg"]);
}
else{
mealImg.addEventListener("error", function(e) {
mealImg.setAttribute("src", "./assets/images/icons/plate_with_cutlery.png");
}
e.onerror = null;
});
//meal name
let mealLabel = document.getElementById("d-mealName");
@ -78,7 +77,6 @@ function setupUpdate(){
//Set value of each input element to current's values
document.getElementById("mealImg").defaultValue = currReview["mealImg"];
document.getElementById("imgAlt").defaultValue = currReview["imgAlt"];
document.getElementById("mealName").defaultValue = currReview["mealName"];
document.getElementById("comments").textContent = currReview["comments"];
document.getElementById("s" + `${currReview["rating"]}`).checked = true;