-
Notifications
You must be signed in to change notification settings - Fork 39
[윤정환] sprint4 #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
addiescode-sj
merged 6 commits into
codeit-bootcamp-frontend:Basic-윤정환
from
khuyjh:Basic-윤정환-sprint4
May 14, 2025
The head ref may contain hidden characters: "Basic-\uC724\uC815\uD658-sprint4"
Merged
[윤정환] sprint4 #139
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
95d038d
Add btn-functions.js, login-signup.js, validate.js
khuyjh 4e794f5
login-signup form요소 유효성 검사 기능 추가, 비밀번호 표시 기능 추가
khuyjh 14972ef
배포 업데이트용 커밋
khuyjh 0c13b34
주석 삭제
khuyjh 1d2f2f6
og:image 경로 변경
khuyjh fd06a3e
함수 명칭 변경 switch -> toggle, isSignupPage 삼항 연산자로 변경
khuyjh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <!-- --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| //모든 input의 유효성 검사를 통과했을 때에만 누를 수 있어야하므로 validate와 작동방식이 달라야함 | ||
| export function toggleBtnStatus() { | ||
| const btn = document.querySelector(".btn--interactions"); | ||
| const errorMessages = document.querySelectorAll(".form__error-msg"); | ||
| const inputs = document.querySelectorAll(".form__input"); | ||
|
|
||
| for (const message of errorMessages) { | ||
| if (message.textContent) { | ||
| btn.setAttribute("disabled", ""); | ||
| btn.classList.add("btn--disabled"); | ||
| return; | ||
| } | ||
| } | ||
| for (const input of inputs) { | ||
| if (!input.value) { | ||
| btn.setAttribute("disabled", ""); | ||
| btn.classList.add("btn--disabled"); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| btn.removeAttribute("disabled"); | ||
| btn.classList.remove("btn--disabled"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { | ||
| isEmpty, | ||
| validateEmail, | ||
| validatePassword, | ||
| validatePasswordConfirm, | ||
| validatePasswordConfirmReverse, | ||
| validateNickname, | ||
| } from "./validate.js"; | ||
| import { toggleBtnStatus } from "./btn-functions.js"; | ||
|
|
||
| function toggleVisibility(event) { | ||
| const btn = event.target.parentElement; | ||
| const passwordInput = btn.previousElementSibling; | ||
| const iconOff = btn.children[0]; | ||
| const iconOn = btn.children[1]; | ||
|
|
||
| if (passwordInput.getAttribute("type") === "password") { | ||
| passwordInput.setAttribute("type", "text"); | ||
| btn.setAttribute("aria-pressed", "true"); | ||
| } else { | ||
| passwordInput.setAttribute("type", "password"); | ||
| btn.setAttribute("aria-pressed", "false"); | ||
| } | ||
| iconOff.classList.toggle("display-none"); | ||
| iconOn.classList.toggle("display-none"); | ||
| } | ||
|
|
||
| function isSignupPage() { | ||
| return window.location.pathname.search("signup") === -1 ? false : true; | ||
| } | ||
|
|
||
| const form = document.querySelector(".container--form"); | ||
| const validateMap = { | ||
| email: validateEmail, | ||
| password: validatePassword, | ||
| "password-confirm": validatePasswordConfirm, | ||
| nickname: validateNickname, | ||
| }; | ||
|
|
||
| form.addEventListener("focusout", (event) => { | ||
| const { id } = event.target; | ||
|
|
||
| if (validateMap[id]) { | ||
| validateMap[id](event); | ||
| //비밀번호확인란부터 입력후 비밀번호를 변경할 시 비밀번호 확인 유효성 검사 | ||
| if (id === "password" && isSignupPage()) { | ||
| const passwordConfirmInput = document.getElementById("password-confirm"); | ||
| const passwordConfirm = passwordConfirmInput.value; | ||
| if (!isEmpty(passwordConfirm)) { | ||
| validatePasswordConfirmReverse(); | ||
| } | ||
| } | ||
| toggleBtnStatus(); | ||
| } | ||
| }); | ||
| form.addEventListener("click", (event) => { | ||
| if (event.target.classList.contains("form__icon")) { | ||
| toggleVisibility(event); | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // common functions | ||
| export function isEmpty(value) { | ||
| return value ? false : true; | ||
| } | ||
|
|
||
| function addInvalid(input) { | ||
| input.classList.add("invalid"); | ||
| } | ||
|
|
||
| function removeInvalid(input) { | ||
| input.classList.remove("invalid"); | ||
| } | ||
|
|
||
| // email functions | ||
| const emailPattern = /^[A-Za-z0-9_\.\-]+@[A-Za-z0-9\-]+\.[A-Za-z0-9\-]+/; | ||
|
|
||
| function checkEmailFormat(email) { | ||
| if (emailPattern.test(email)) { | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| export function validateEmail(event) { | ||
| const emailInput = event.target; | ||
| const email = emailInput.value; | ||
| let divErrorMessage = document.querySelector(".error-msg--email"); | ||
|
|
||
| if (isEmpty(email)) { | ||
| divErrorMessage.textContent = "이메일을 입력해주세요"; | ||
| addInvalid(emailInput); | ||
| } else if (!checkEmailFormat(email)) { | ||
| divErrorMessage.textContent = "잘못된 이메일 형식입니다"; | ||
| addInvalid(emailInput); | ||
| } else { | ||
| divErrorMessage.textContent = ""; | ||
| removeInvalid(emailInput); | ||
| } | ||
| } | ||
|
|
||
| // password functions | ||
| function checkPasswordFormat(password) { | ||
| if (password.length < 8) { | ||
| return false; | ||
| } else { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| function checkPassword(password, passwordConfirm) { | ||
| return password === passwordConfirm ? true : false; | ||
| } | ||
|
|
||
| export function validatePassword(event) { | ||
| const passwordInput = event.target; | ||
| const password = passwordInput.value; | ||
| let divErrorMessage = document.querySelector(".error-msg--password"); | ||
|
|
||
| if (isEmpty(password)) { | ||
| divErrorMessage.textContent = "비밀번호를 입력해주세요"; | ||
| addInvalid(passwordInput); | ||
| } else if (!checkPasswordFormat(password)) { | ||
| divErrorMessage.textContent = "비밀번호를 8자 이상 입력해주세요"; | ||
| addInvalid(passwordInput); | ||
| } else { | ||
| divErrorMessage.textContent = ""; | ||
| removeInvalid(passwordInput); | ||
| } | ||
| } | ||
|
|
||
| export function validatePasswordConfirm(event) { | ||
| const passwordInput = document.getElementById("password"); | ||
| const password = passwordInput.value; | ||
| const passwordConfirmInput = event.target; | ||
| const passwordConfirm = passwordConfirmInput.value; | ||
| let divErrorMessage = document.querySelector(".error-msg--password-confirm"); | ||
|
|
||
| if (!checkPassword(password, passwordConfirm)) { | ||
| divErrorMessage.textContent = "비밀번호가 일치하지 않습니다"; | ||
| addInvalid(passwordConfirmInput); | ||
| } else { | ||
| divErrorMessage.textContent = ""; | ||
| removeInvalid(passwordConfirmInput); | ||
| } | ||
| } | ||
|
|
||
| //password유효성 검사를 하면서 password-confirm검사를 하기 위해 event가 아닌 고정으로 값을 가져오도록 함 | ||
| export function validatePasswordConfirmReverse() { | ||
| const passwordInput = document.getElementById("password"); | ||
| const password = passwordInput.value; | ||
| const passwordConfirmInput = document.getElementById("password-confirm"); | ||
| const passwordConfirm = passwordConfirmInput.value; | ||
| let divErrorMessage = document.querySelector(".error-msg--password-confirm"); | ||
|
|
||
| if (!checkPassword(password, passwordConfirm)) { | ||
| divErrorMessage.textContent = "비밀번호가 일치하지 않습니다"; | ||
| addInvalid(passwordConfirmInput); | ||
| } else { | ||
| divErrorMessage.textContent = ""; | ||
| removeInvalid(passwordConfirmInput); | ||
| } | ||
| } | ||
|
|
||
| //nickname functions | ||
| export function validateNickname(event) { | ||
| const nicknameInput = event.target; | ||
| const nickname = nicknameInput.value; | ||
| let divErrorMessage = document.querySelector(".error-msg--nickname"); | ||
|
|
||
| if (isEmpty(nickname)) { | ||
| divErrorMessage.textContent = "닉네임을 입력해주세요"; | ||
| addInvalid(nicknameInput); | ||
| } else { | ||
| divErrorMessage.textContent = ""; | ||
| removeInvalid(nicknameInput); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
email, password, password confirm, nickname 지금은 이렇게 네개지만 지금과 같은 구조라면 폼 요소가 더 늘어날때 작성되는 코드양도 같이 늘어나겠죠?
재사용 가능한 단위까지 로직을 쪼개서 단일 책임을 가지고있는 함수를 만들면 어떨까요?
코드 예시를 드려볼게요 :)