Skip to content

Commit

Permalink
remove not used function and rename functions and variables
Browse files Browse the repository at this point in the history
  • Loading branch information
gudzsv committed Feb 14, 2024
1 parent 03d7105 commit 399c4b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
4 changes: 0 additions & 4 deletions src/js/1-gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,3 @@ new SimpleLightbox('.gallery a', {
captionsData: 'alt',
captionDelay: 250,
});

function removeFirstLaseChar(string) {
return string.slice(1, string.length - 1);
}
17 changes: 9 additions & 8 deletions src/js/2-form.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const formState = 'feedback-form-state';
const from = document.querySelector('.feedback-form');
const form = document.querySelector('.feedback-form');

// get local storage data
const localState = JSON.parse(localStorage.getItem(formState));
Expand All @@ -12,10 +12,10 @@ if (localState) {
}

// event to fill in form state object **//
from.addEventListener('input', onInputSaveToLocalStorage);
form.addEventListener('input', onInputSaveToLocalStorage);

// save form form data to local storage **//
from.addEventListener('submit', onSubmitForm);
form.addEventListener('submit', onSubmitForm);

function onInputSaveToLocalStorage(event) {
const key = event.target.name;
Expand All @@ -32,7 +32,7 @@ function onSubmitForm(event) {

const formData = new FormData(event.target);
const formDataObj = Object.fromEntries(formData.entries());

console.log(formDataObj);
if (validateFormFields(formDataObj)) {
// according requirement of Homework 9
console.log('submit', formDataObj);
Expand All @@ -47,21 +47,22 @@ function validateFormFields(formDataObj) {
let isValid = true;
for (const key in formDataObj) {
if (!formDataObj[key]) {
addError(document.querySelector(`[name="${key}"]`));
addBorderInputError(document.querySelector(`[name="${key}"]`));
console.log(document.querySelector(`[name="${key}"]`));
isValid = false;
}
if (formDataObj[key]) {
removeError(document.querySelector(`[name="${key}"]`));
removeBorderInputError(document.querySelector(`[name="${key}"]`));
}
}

return isValid;
}

function addError(input) {
function addBorderInputError(input) {
input.classList.add('error');
}

function removeError(input) {
function removeBorderInputError(input) {
input.classList.remove('error');
}

0 comments on commit 399c4b1

Please sign in to comment.