mirror of
https://github.com/cse110-fa22-group29/cse110-fa22-group29.git
synced 2024-11-13 22:36:17 +00:00
Added local img storage to updating
This commit is contained in:
parent
3e909ed381
commit
f340f3ed82
@ -26,9 +26,14 @@
|
|||||||
<!----> <form id="update-food-entry" class="hidden">
|
<!----> <form id="update-food-entry" class="hidden">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Pic:</legend>
|
<legend>Pic:</legend>
|
||||||
<label for="mealImage">
|
Choose Input type:
|
||||||
|
<select id="select" name="select">
|
||||||
|
<option value="file">File Upload</option>
|
||||||
|
<option value="url">From an URL</option>
|
||||||
|
</select>
|
||||||
|
<label for="mealImage" id="source">
|
||||||
Source:
|
Source:
|
||||||
<input type="text" id="mealImg" name="mealImg">
|
<input type="file" accept="image/*" id="mealImg" name="mealImg">
|
||||||
</label>
|
</label>
|
||||||
<label for="image-alt">
|
<label for="image-alt">
|
||||||
Alt Text:
|
Alt Text:
|
||||||
|
@ -55,6 +55,45 @@ function setupUpdate(){
|
|||||||
tagContainer.append(newTag);
|
tagContainer.append(newTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* change the input source of the image between local file and URL
|
||||||
|
* depending on user's selection
|
||||||
|
*/
|
||||||
|
let select = document.getElementById("select");
|
||||||
|
select.addEventListener("change", function() {
|
||||||
|
const input = document.getElementById('source');
|
||||||
|
|
||||||
|
if (select.value == "file") {
|
||||||
|
input.innerHTML = `
|
||||||
|
Source:
|
||||||
|
<input type="file" accept="image/*" id="mealImg" name="mealImg">
|
||||||
|
`
|
||||||
|
}
|
||||||
|
//TODO: change to photo taking for sprint 3
|
||||||
|
else {
|
||||||
|
input.innerHTML = `
|
||||||
|
Source:
|
||||||
|
<input type="text" id="mealImg" name="mealImg">
|
||||||
|
`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//addressing sourcing image from local file
|
||||||
|
let imgDataURL = "";
|
||||||
|
document.getElementById("mealImg").addEventListener("change", function() {
|
||||||
|
const reader = new FileReader();
|
||||||
|
|
||||||
|
//store image data URL after successful image load
|
||||||
|
reader.addEventListener("load", ()=>{
|
||||||
|
imgDataURL = reader.result;
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
//convert image file into data URL for local storage
|
||||||
|
reader.readAsDataURL(document.getElementById("mealImg").files[0]);
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
//Take formdata values as newData when submit
|
//Take formdata values as newData when submit
|
||||||
form.addEventListener("submit", function(){
|
form.addEventListener("submit", function(){
|
||||||
/*
|
/*
|
||||||
@ -69,6 +108,9 @@ function setupUpdate(){
|
|||||||
if (`${key}` !== "tag-form") {
|
if (`${key}` !== "tag-form") {
|
||||||
newData[`${key}`] = `${value}`;
|
newData[`${key}`] = `${value}`;
|
||||||
}
|
}
|
||||||
|
if (`${key}` === "mealImg" && select.value == "file") {
|
||||||
|
newData["mealImg"] = imgDataURL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
newData["tags"] = [];
|
newData["tags"] = [];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user