Page 1 sur 1

Modifier un film via modal

Posté : 06 nov. 2021, 21:45
par Daniel Prudent
Bonjour j"ai besoin d'aide svp. Quand je clique sur modifier film. je veux faire en sorte de pouvoir modifier les donner de mon film

HTML
<!-- Modal -->
<div class="modal fade" id="staticBackdrop1" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="staticBackdropLabel1">Modifier film</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>

<form class="row g-3 needs-validation"action="submit" novalidate method="POST" id="form">
<div class="modal-body">
<p><h6>Titre:</h6>
<textarea class="form-control" id="titre1"></textarea>
<p><h6>Numero:</h6>
<textarea class="form-control" id="numero1"></textarea>
<p><h6>Annee:</h6>
<textarea class="form-control" id="annee1"></textarea>
<p><h6>Duree:</h6>
<textarea class="form-control" id="duree1"></textarea>
<p><h6>Categorie:</h6>
<textarea class="form-control" id="categorie1"></textarea>
<p><h6>Directeur:</h6>
<textarea class="form-control" id="directeur1"></textarea>
<p><h6>Acteur:</h6>
<textarea class="form-control" id="acteur1"></textarea>
<p><h6>Description:</h6>
<textarea class="form-control" id="description1"></textarea>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fermer</button>
<button type="submit" onclick="modifierFilm1()" class="btn btn-primary">Modifier</button>
</div>
</div>
</div>

</div>


JS
function addFilm() {

let id = document.getElementById('numero').value;
let title = document.getElementById('titre').value;
let year = document.getElementById('annee').value;
let runtime = document.getElementById('duree').value;
let genres = document.getElementById('categorie').value;
let director = document.getElementById('directeur').value;
let actors = document.getElementById('acteur').value;
let plot = document.getElementById('description').value;
// let posterUrl = document.getElementById('photo').value;



let unFilm = { "id": id, "title": title, "year": year, "runtime": runtime, "genres": genres, "director": director, "actors": actors, "plot": plot };
myArray.push(unFilm);
console.log(myArray);

}

function addFilmAndRefreshPage() {
addFilm();
buildTable(myArray);
}



let enleverFilm = (leFilm) => {
let racine = leFilm;
alert(JSON.stringify(racine));
}


$("#form").submit(function (event) {
event.preventDefault(); //prevent default action
var post_url = $(this).attr("submit"); //get form action url
var form_data = $(this).serialize(id, title, year, runtime, genres, director, actors, plot); //Encode form elements for submission

$.post(post_url, form_data, function (response) {
$("#server-results").html(response);
});
});

function modifierFilm(index) {
console.log(index)
document.getElementById('numero1').value = myArray[index].id;
document.getElementById('titre1').value = myArray[index].title;
document.getElementById('annee1').value = myArray[index].year;
document.getElementById('duree1').value = myArray[index].runtime;
document.getElementById('categorie1').value = myArray[index].genres;
document.getElementById('directeur1').value = myArray[index].director;
document.getElementById('acteur1').value = myArray[index].actors;
document.getElementById('description1').value = myArray[index].plot;


}
function modifierFilm1() {
var id = document.getElementById('numero1').value

for (var i = 0; i < id.length; i++) {
var unFilm = document.getElementById("numero1").value;
var unFilm = document.getElementById('title1').value
var unFilm = document.getElementById('annee1').value
var unFilm = document.getElementById('duree1').value
var unFilm = document.getElementById('categorie1').value
var unFilm = document.getElementById('directeur1').value
var unFilm = document.getElementById('acteur1').value
var unFilm = document.getElementById('description1').value
myArray.splice(unFilm);
//document.getElementById("title").innerHTML = title;

}
}