normalisation blog + gestion images
This commit is contained in:
@@ -3,6 +3,7 @@ const messages = document.getElementById("messages");
|
||||
|
||||
const imgField = document.getElementById("articleImage");
|
||||
const titleField = document.getElementById("articleTitle");
|
||||
const imgPreview = document.getElementById("imagePreview");
|
||||
const contentField = document.getElementById("articleContent");
|
||||
const categoryField = document.getElementById("articleCategory");
|
||||
const publishedField = document.getElementById("articlePublished");
|
||||
@@ -31,6 +32,21 @@ function imageValide(file) {
|
||||
return ["image/jpeg", "image/png", "image/gif"].includes(file.type);
|
||||
}
|
||||
|
||||
// Preview image on selection
|
||||
imgField.addEventListener("change", function () {
|
||||
const file = imgField.files && imgField.files[0];
|
||||
if (!file || !imageValide(file)) {
|
||||
if (imgPreview) {
|
||||
imgPreview.src = "";
|
||||
imgPreview.classList.add("d-none");
|
||||
}
|
||||
return;
|
||||
}
|
||||
const url = URL.createObjectURL(file);
|
||||
imgPreview.src = url;
|
||||
imgPreview.classList.remove("d-none");
|
||||
});
|
||||
|
||||
|
||||
form.addEventListener("submit", function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user