Skip to content

Commit

Permalink
fix: 화살표 함수로, 콜백함수 리팩토링으로 인한 호이스팅이 안되어 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Daewony committed Oct 11, 2024
1 parent 38705e0 commit 8605ced
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
10 changes: 6 additions & 4 deletions common/js/form-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const passwordConfirm = document.getElementById('password-confirm');
const formButton = document.getElementById('form-button');

// -----폼 제출 시 이벤트 처리-----
form.addEventListener('submit', handleFormSubmit);

const handleFormSubmit = (e) => {
e.preventDefault();
Expand All @@ -32,13 +31,16 @@ const handleFormSubmit = (e) => {
}
};

form.addEventListener('submit', handleFormSubmit);

// -----입력 시 제출 버튼 상태 업데이트-----
form.addEventListener('input', updateSubmitButtonState);

const updateSubmitButtonState = () => {
setSubmitButtonState();
};

form.addEventListener('input', updateSubmitButtonState);

// 제출 버튼 활성화 상태 설정 함수
const setSubmitButtonState = () => {
const currentPage = window.location.pathname;
Expand Down Expand Up @@ -107,13 +109,13 @@ const isUserExist = (email, password) => {
};

// -----포커스 아웃 시 유효성 검사-----
form.addEventListener('focusout', handleFocusOut);

const handleFocusOut = (e) => {
const validateElementId = e.target.id;
validateForm(validateElementId);
};

form.addEventListener('focusout', handleFocusOut);

const validateForm = (validateElementId) => {
const validationHandlers = {
email: () => validateEmail(),
Expand Down
24 changes: 12 additions & 12 deletions common/js/modal.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
const modal = document.getElementById('error-message-modal');
const closeModalButton = document.querySelector('.close-modal-button');

// 모달 닫기 버튼 이벤트
closeModalButton.addEventListener('click', () => {
closeModal();
});
export const closeModal = () => {
modal.close();
};

// -----모달 닫기 버튼 이벤트-----
closeModalButton.addEventListener('click', closeModal);

// -----모달 외부 클릭 시 닫기-----

// 모달 외부 클릭 시 닫기
modal.addEventListener('click', (e) => {
if (isModalOutSideClicked) {
const handleCloseModal = (e) => {
if (isModalOutSideClicked(e)) {
closeModal();
}
});
};
modal.addEventListener('click', handleCloseModal);

// 모달 외부 클릭 했는지 확인
const isModalOutSideClicked = (e) => {
Expand All @@ -28,7 +32,3 @@ const isModalOutSideClicked = (e) => {
export const showModal = () => {
modal.showModal();
};

export const closeModal = () => {
modal.close();
};

0 comments on commit 8605ced

Please sign in to comment.