Skip to content

Commit

Permalink
feat (modal) : recup form inputs values in log (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
codexarama committed May 10, 2021
1 parent 597b65c commit b69e155
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions js/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ const confirm = document.querySelector('.form__confirmation');
const submitBtn = document.querySelector('#submit');
let closeModalBtn = document.querySelectorAll('.form__close');
// console.log(closeModalBtn);
const closeConfirmBtn = document.querySelector('.close-confirm');

// FORM
const form = document.querySelector(".form")
const form = document.querySelector('.form');
const formData = document.querySelectorAll('.formData');

// INPUTS
Expand All @@ -26,18 +25,22 @@ modalBtn.addEventListener(
(launchModal = (e) => {
e.preventDefault();
modal.style.display = 'block';
location.hash = 'me contacter'
location.hash = 'me contacter';
})
);

// close modal(s) event
closeModalBtn.forEach((btn) => btn.addEventListener("click", closeModal = () => {
modal.style.display = "none";
}));
closeModalBtn.forEach((btn) =>
btn.addEventListener(
'click',
(closeModal = () => {
modal.style.display = 'none';
})
)
);

// CONFIRMATION D'ENVOI DU MESSAGE
form.addEventListener('submit', function (e) {
e.preventDefault();
if (checkValidity) {
modalBody.style.display = 'none';
confirm.style.opacity = '1';
Expand All @@ -48,6 +51,7 @@ form.addEventListener('submit', function (e) {
// VERIFICATION DES SAISIES
const inputs = document.querySelectorAll('input');
const textarea = document.querySelectorAll('textarea');
console.log(textarea.value);

const checkValidity = (input) => {
input.addEventListener('invalid', (e) => {
Expand Down Expand Up @@ -76,10 +80,6 @@ const checkValidity = (input) => {

// CHECKVALIDITY TEXTAREA ?!

// recuperation des saisies
Array.from(inputs).forEach(checkValidity);
Array.from(textarea).forEach(checkValidity);

// MESSAGES
// Error
const dataError = (input, message) => {
Expand All @@ -94,3 +94,18 @@ const dataSuccess = (input, message) => {
const small = formData.querySelector('small');
small.innerText = message;
};

// recuperation des saisies
Array.from(inputs).forEach(checkValidity);
Array.from(textarea).forEach(checkValidity);

// AFFICHE LES SAISIES DANS LA CONSOLE
// ---------- NE FONCTIONNE PAS ---------- //
form.addEventListener('submit', function (e) {
e.preventDefault();
console.log(`Prénom : ${firstName.value}`);
console.log(`Nom : ${lastName.value}`);
console.log(`Email : ${email.value}`);
console.log(`Message : ${message.value}`);
closeModal();
});

0 comments on commit b69e155

Please sign in to comment.