mise a jour categorie (liste deroulante et remplissage obligatoire) + mise a jour checkbox + insertion de TinyMCE (pas finis)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
const form = document.getElementById('ajouterArticleForm');
|
||||
const imgField = document.getElementById('articleImage');
|
||||
const titleField = document.getElementById('articleTitle');
|
||||
const contentField = document.getElementById('articleContent');
|
||||
const categoryField = document.getElementById('articleCategory');
|
||||
const publishedField = document.getElementById('articlePublished');
|
||||
|
||||
@@ -18,6 +17,8 @@ form.addEventListener('submit', function(e) {
|
||||
|
||||
const titre = titleField.value.trim().toLowerCase();
|
||||
const fichierImage = imgField.files[0];
|
||||
const contenu = tinymce.get("articleContent").getContent(); // ← CORRECTION IMPORTANTE
|
||||
const categorie = categoryField.value;
|
||||
|
||||
// Reset messages
|
||||
errorEmpty.classList.add('d-none');
|
||||
@@ -25,8 +26,16 @@ form.addEventListener('submit', function(e) {
|
||||
errorExists.classList.add('d-none');
|
||||
successMsg.classList.add('d-none');
|
||||
|
||||
// Catégorie obligatoire
|
||||
if (categorie === "") {
|
||||
errorEmpty.textContent = "Veuillez choisir une catégorie.";
|
||||
errorEmpty.classList.remove('d-none');
|
||||
return;
|
||||
}
|
||||
|
||||
// Titre obligatoire
|
||||
if (titre === "") {
|
||||
errorEmpty.textContent = "Le titre de l'article est obligatoire.";
|
||||
errorEmpty.classList.remove('d-none');
|
||||
return;
|
||||
}
|
||||
@@ -37,6 +46,13 @@ form.addEventListener('submit', function(e) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Contenu obligatoire
|
||||
if (contenu.trim() === "") {
|
||||
errorEmpty.textContent = "Le contenu de l'article ne peut pas être vide.";
|
||||
errorEmpty.classList.remove('d-none');
|
||||
return;
|
||||
}
|
||||
|
||||
// Image invalide
|
||||
if (fichierImage) {
|
||||
const validFormats = ['image/jpeg', 'image/png'];
|
||||
@@ -52,8 +68,17 @@ form.addEventListener('submit', function(e) {
|
||||
// Succès
|
||||
successMsg.classList.remove('d-none');
|
||||
|
||||
// Redirection après 1 seconde
|
||||
// Redirection
|
||||
setTimeout(() => {
|
||||
window.location.href = "../html/liste_categorie_article.html";
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
// TinyMCE
|
||||
tinymce.init({
|
||||
selector: '#articleContent',
|
||||
height: 400,
|
||||
language: 'fr',
|
||||
plugins: 'lists fullscreen',
|
||||
toolbar: 'undo redo | bold italic underline | bullist numlist | fullscreen',
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user