Advertisement
Guest User

Untitled

a guest
Dec 13th, 2023
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.  
  3.   let fields = Array.from(document.querySelectorAll('input')).slice(0, 5)
  4.   let nextBtn = document.querySelector('#next-btn')
  5.   let infoSection = document.querySelector('.info-list')
  6.   let confirmSection = document.querySelector('.confirm-list')
  7.   let verification = document.getElementById('verification');
  8.  
  9.     nextBtn.addEventListener("click", onClick);
  10.   function onClick(e) {
  11.     e.preventDefault();
  12.     let[firstName, lastName, dateIn, dateOut, count] = fields
  13.     if(!firstName.value || !lastName.value || !dateIn.value
  14.        || !dateOut.value || !count.value) return
  15.  
  16.     // point 1, 2
  17.     infoSection.innerHTML = `<li class="reservation-content">
  18.        <article>
  19.          <h3>Name: ${firstName.value} ${lastName.value}</h3>
  20.          <p>From date: ${dateIn.value}</p>
  21.          <p>To date: ${dateOut.value}</p>
  22.          <p>For ${count.value} people</p>
  23.        </article>
  24.        <button class="edit-btn">Edit</button>
  25.        <button class="continue-btn">Continue</button>
  26.     </li>
  27.     `
  28.  
  29.         let editFirstName = firstName.value;
  30.         let editLastName = lastName.value;
  31.         let editDateIn = dateIn.value;
  32.         let editDateOut = dateOut.value;
  33.         let editcount = count.value;
  34.  
  35.         firstName.value = "";
  36.     lastName.value = "";
  37.     dateIn.value = "";
  38.     dateOut.value = "";
  39.     count.value = "";
  40.    buttonsState(true)
  41.  
  42.    document.querySelector('.edit-btn').addEventListener('click', onEdit)
  43.   function onEdit(){
  44.         firstName.value = editFirstName;
  45.         lastName.value = editLastName;
  46.         dateIn.value = editDateIn;
  47.         dateOut.value = editDateOut;
  48.         count.value = editcount;
  49.    buttonsState(false)
  50.    infoSection.innerHTML = ''
  51.  
  52. }
  53.  
  54. function buttonsState(nextDisabled = true){  
  55.   if(nextDisabled){
  56.       nextBtn.disabled = true
  57.       document.querySelector('.edit-btn').disabled = false
  58.       document.querySelector('.continue-btn').disabled = false
  59.   } else {
  60.       nextBtn.disabled = false
  61.      if(document.querySelector('.edit-btn') != null) {      // point 3
  62.       document.querySelector('.edit-btn').disabled = true
  63.       document.querySelector('.continue-btn').disabled = true
  64.      }
  65.   }
  66. }
  67.  
  68. document.querySelector('.continue-btn').addEventListener('click', onContinue)
  69. function onContinue(){
  70.  
  71.     // point 1, 2, 4
  72.   confirmSection.innerHTML = `<li class="reservation-content">
  73.        <article>
  74.          <h3>Name: ${editFirstName} ${editLastName}</h3>
  75.          <p>From date: ${editDateIn}</p>
  76.          <p>To date: ${editDateOut}</p>
  77.          <p>For ${editcount} people</p>
  78.        </article>
  79.   <button class="confirm-btn">Confirm</button>
  80.   <button class="cancel-btn">Cancel</button>
  81. </li>
  82. `
  83. infoSection.innerHTML = ''
  84.  
  85. document.querySelector('.confirm-btn').addEventListener('click', onConfirm);
  86.   function onConfirm() {
  87.     confirmSection.innerHTML = ''
  88.      buttonsState(false)
  89.  
  90.       verification.setAttribute('class', 'reservation-confirmed');
  91.       verification.textContent = 'Confirmed.';
  92.   }
  93.  
  94.   document.querySelector('.cancel-btn').addEventListener('click',onCancel);
  95.   function onCancel() {
  96.     confirmSection.innerHTML = ''
  97.       buttonsState(false)
  98.  
  99.       verification.setAttribute('class', 'reservation-cancelled');
  100.       verification.textContent = 'Cancelled.';
  101.  
  102.   }
  103.  }
  104. }  
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement