addresses case where image is not updated

This commit is contained in:
Henry Feng 2022-11-20 14:27:24 -08:00
parent f340f3ed82
commit 3c7b5f7f4e

View File

@ -82,6 +82,7 @@ function setupUpdate(){
//addressing sourcing image from local file //addressing sourcing image from local file
let imgDataURL = ""; let imgDataURL = "";
document.getElementById("mealImg").addEventListener("change", function() { document.getElementById("mealImg").addEventListener("change", function() {
console.log("reading used");
const reader = new FileReader(); const reader = new FileReader();
//store image data URL after successful image load //store image data URL after successful image load
@ -108,7 +109,11 @@ function setupUpdate(){
if (`${key}` !== "tag-form") { if (`${key}` !== "tag-form") {
newData[`${key}`] = `${value}`; newData[`${key}`] = `${value}`;
} }
if (`${key}` === "mealImg" && select.value == "file") { //Account for the case where image is not updated
if (`${key}` === "mealImg" && document.getElementById("mealImg").value === "") {
newData["mealImg"] = currReview["mealImg"];
}
else if (`${key}` === "mealImg" && select.value == "file") {
newData["mealImg"] = imgDataURL; newData["mealImg"] = imgDataURL;
} }
} }