-
Notifications
You must be signed in to change notification settings - Fork 39
[이승민] Sprint4 #151
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
The head ref may contain hidden characters: "Basic-\uC774\uC2B9\uBBFC-sprint4"
[이승민] Sprint4 #151
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,3 +109,7 @@ | |
| max-width: 640px; | ||
| margin: 0 auto; | ||
| } | ||
|
|
||
| .input-error { | ||
| border: 1px solid red !important; | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💊 제안
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💊 제안 우선은 간단하게 아래처럼 분리하셔도 좋을 것 같아요. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,184 @@ | ||||||||||||||||||||||||||||||||||||||
| document.addEventListener("DOMContentLoaded", function () { | ||||||||||||||||||||||||||||||||||||||
| const form = document.querySelector("form.auth-form"); | ||||||||||||||||||||||||||||||||||||||
| if (!form) return; | ||||||||||||||||||||||||||||||||||||||
| const button = form.querySelector("button.auth-button"); | ||||||||||||||||||||||||||||||||||||||
| button.disabled = true; | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+4
to
+5
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❗️ 수정요청 |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // 전체 폼 유효성 검사 | ||||||||||||||||||||||||||||||||||||||
| function checkFormValidity() { | ||||||||||||||||||||||||||||||||||||||
| let valid = true; | ||||||||||||||||||||||||||||||||||||||
| const inputs = form.querySelectorAll("input"); | ||||||||||||||||||||||||||||||||||||||
| inputs.forEach(function (input) { | ||||||||||||||||||||||||||||||||||||||
| if (input.value.trim() === "") { | ||||||||||||||||||||||||||||||||||||||
| valid = false; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
| if (form.querySelectorAll(".error-message").length > 0) { | ||||||||||||||||||||||||||||||||||||||
| valid = false; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| button.disabled = !valid; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+8
to
+20
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💊 제안
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // 이메일 | ||||||||||||||||||||||||||||||||||||||
| const emailInput = document.getElementById("email"); | ||||||||||||||||||||||||||||||||||||||
| if (emailInput) { | ||||||||||||||||||||||||||||||||||||||
| emailInput.addEventListener("blur", validateEmail); | ||||||||||||||||||||||||||||||||||||||
| emailInput.addEventListener("input", validateEmail); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| function validateEmail() { | ||||||||||||||||||||||||||||||||||||||
| const emailValue = emailInput.value.trim(); | ||||||||||||||||||||||||||||||||||||||
| let errorMessage = emailInput.closest(".input-group").querySelector(".error-message"); | ||||||||||||||||||||||||||||||||||||||
| if (!emailValue) { | ||||||||||||||||||||||||||||||||||||||
| emailInput.classList.add("input-error"); | ||||||||||||||||||||||||||||||||||||||
| if (!errorMessage) { | ||||||||||||||||||||||||||||||||||||||
| errorMessage = document.createElement("span"); | ||||||||||||||||||||||||||||||||||||||
| errorMessage.className = "error-message"; | ||||||||||||||||||||||||||||||||||||||
| errorMessage.style.cssText = "color: red; font-size: 14px; display: block; margin-top: 4px;"; | ||||||||||||||||||||||||||||||||||||||
| errorMessage.innerText = "이메일을 입력해주세요."; | ||||||||||||||||||||||||||||||||||||||
| emailInput.closest(".input-group").appendChild(errorMessage); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+34
to
+38
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💊 제안
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| errorMessage.innerText = "이메일을 입력해주세요."; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||||||||||||||||||||||||||||||||||||||
| if (!emailRegex.test(emailValue)) { | ||||||||||||||||||||||||||||||||||||||
| emailInput.classList.add("input-error"); | ||||||||||||||||||||||||||||||||||||||
| if (!errorMessage) { | ||||||||||||||||||||||||||||||||||||||
| errorMessage = document.createElement("span"); | ||||||||||||||||||||||||||||||||||||||
| errorMessage.className = "error-message"; | ||||||||||||||||||||||||||||||||||||||
| errorMessage.style.cssText = "color: red; font-size: 14px; display: block; margin-top: 4px;"; | ||||||||||||||||||||||||||||||||||||||
| errorMessage.innerText = "잘못된 이메일 형식입니다"; | ||||||||||||||||||||||||||||||||||||||
| emailInput.closest(".input-group").appendChild(errorMessage); | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| errorMessage.innerText = "잘못된 이메일 형식입니다"; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| emailInput.classList.remove("input-error"); | ||||||||||||||||||||||||||||||||||||||
| if (errorMessage) errorMessage.remove(); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| checkFormValidity(); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // 비밀번호 | ||||||||||||||||||||||||||||||||||||||
| const passwordInput = document.getElementById("password"); | ||||||||||||||||||||||||||||||||||||||
| if (passwordInput) { | ||||||||||||||||||||||||||||||||||||||
| passwordInput.addEventListener("blur", validatePassword); | ||||||||||||||||||||||||||||||||||||||
| passwordInput.addEventListener("input", validatePassword); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| function validatePassword() { | ||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💊 제안 function validateEmail() {
const email = emailInput.value.trim();
const errorMessage = getErrorMessageEl(
emailInput,
"이메일을 입력해주세요."
);
if (!email) {
showError(emailInput, errorMessage, "이메일을 입력해주세요.");
} else if (!isValidEmail(emailValue)) {
showError(emailInput, errorMessage, "잘못된 이메일 형식입니다");
} else {
hideError(emailInput, errorMessage);
}
checkFormValidity();
}
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
function getErrorMessageEl(input, defaultMessage) {
const errorMessage =
input.closest(".input-group").querySelector(".error-message") ??
document.createElement("span");
errorMessage.className = "error-message";
errorMessage.innerText = defaultMessage;
input.closest(".input-group").appendChild(errorMessage);
return errorMessage;
}
function showError(input, errorMessage, message) {
input.classList.add("input-error");
errorMessage.innerText = message;
}
function hideError(input, errorMessage) {
input.classList.remove("input-error");
if (errorMessage) errorMessage.remove();
} |
||||||||||||||||||||||||||||||||||||||
| const passwordValue = passwordInput.value.trim(); | ||||||||||||||||||||||||||||||||||||||
| let errorMessage = passwordInput.closest(".input-group").querySelector(".error-message"); | ||||||||||||||||||||||||||||||||||||||
| if (!passwordValue) { | ||||||||||||||||||||||||||||||||||||||
| passwordInput.classList.add("input-error"); | ||||||||||||||||||||||||||||||||||||||
| if (!errorMessage) { | ||||||||||||||||||||||||||||||||||||||
| errorMessage = document.createElement("span"); | ||||||||||||||||||||||||||||||||||||||
| errorMessage.className = "error-message"; | ||||||||||||||||||||||||||||||||||||||
| errorMessage.style.cssText = "color: red; font-size: 14px; display: block; margin-top: 4px;"; | ||||||||||||||||||||||||||||||||||||||
| errorMessage.innerText = "비밀번호를 입력해주세요."; | ||||||||||||||||||||||||||||||||||||||
| passwordInput.closest(".input-group").appendChild(errorMessage); | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| errorMessage.innerText = "비밀번호를 입력해주세요."; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } else if (passwordValue.length < 8) { | ||||||||||||||||||||||||||||||||||||||
| passwordInput.classList.add("input-error"); | ||||||||||||||||||||||||||||||||||||||
| if (!errorMessage) { | ||||||||||||||||||||||||||||||||||||||
| errorMessage = document.createElement("span"); | ||||||||||||||||||||||||||||||||||||||
| errorMessage.className = "error-message"; | ||||||||||||||||||||||||||||||||||||||
| errorMessage.style.cssText = "color: red; font-size: 14px; display: block; margin-top: 4px;"; | ||||||||||||||||||||||||||||||||||||||
| errorMessage.innerText = "비밀번호를 8자 이상 입력해주세요."; | ||||||||||||||||||||||||||||||||||||||
| passwordInput.closest(".input-group").appendChild(errorMessage); | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| errorMessage.innerText = "비밀번호를 8자 이상 입력해주세요."; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| passwordInput.classList.remove("input-error"); | ||||||||||||||||||||||||||||||||||||||
| if (errorMessage) errorMessage.remove(); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if (passwordCheckInput) { | ||||||||||||||||||||||||||||||||||||||
| validatePasswordCheck(); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| checkFormValidity(); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // 닉네임 | ||||||||||||||||||||||||||||||||||||||
| const nicknameInput = document.getElementById("nickname"); | ||||||||||||||||||||||||||||||||||||||
| if (nicknameInput) { | ||||||||||||||||||||||||||||||||||||||
| nicknameInput.addEventListener("blur", validateNickname); | ||||||||||||||||||||||||||||||||||||||
| nicknameInput.addEventListener("input", validateNickname); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| function validateNickname() { | ||||||||||||||||||||||||||||||||||||||
| const nicknameValue = nicknameInput.value.trim(); | ||||||||||||||||||||||||||||||||||||||
| let errorMessage = nicknameInput.closest(".input-group").querySelector(".error-message"); | ||||||||||||||||||||||||||||||||||||||
| if (!nicknameValue) { | ||||||||||||||||||||||||||||||||||||||
| nicknameInput.classList.add("input-error"); | ||||||||||||||||||||||||||||||||||||||
| if (!errorMessage) { | ||||||||||||||||||||||||||||||||||||||
| errorMessage = document.createElement("span"); | ||||||||||||||||||||||||||||||||||||||
| errorMessage.className = "error-message"; | ||||||||||||||||||||||||||||||||||||||
| errorMessage.style.cssText = "color: red; font-size: 14px; display: block; margin-top: 4px;"; | ||||||||||||||||||||||||||||||||||||||
| errorMessage.innerText = "닉네임을 입력해주세요."; | ||||||||||||||||||||||||||||||||||||||
| nicknameInput.closest(".input-group").appendChild(errorMessage); | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| errorMessage.innerText = "닉네임을 입력해주세요."; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| nicknameInput.classList.remove("input-error"); | ||||||||||||||||||||||||||||||||||||||
| if (errorMessage) errorMessage.remove(); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| checkFormValidity(); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // 비밀번호 - 회원가입 | ||||||||||||||||||||||||||||||||||||||
| const passwordCheckInput = document.getElementById("passwordCheck"); | ||||||||||||||||||||||||||||||||||||||
| if (passwordCheckInput) { | ||||||||||||||||||||||||||||||||||||||
| passwordCheckInput.addEventListener("blur", validatePasswordCheck); | ||||||||||||||||||||||||||||||||||||||
| passwordCheckInput.addEventListener("input", validatePasswordCheck); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| function validatePasswordCheck() { | ||||||||||||||||||||||||||||||||||||||
| if (passwordInput && passwordCheckInput) { | ||||||||||||||||||||||||||||||||||||||
| const passwordValue = passwordInput.value; | ||||||||||||||||||||||||||||||||||||||
| const passwordCheckValue = passwordCheckInput.value; | ||||||||||||||||||||||||||||||||||||||
| let errorMessage = passwordCheckInput.closest(".input-group").querySelector(".error-message"); | ||||||||||||||||||||||||||||||||||||||
| if (passwordValue !== passwordCheckValue) { | ||||||||||||||||||||||||||||||||||||||
| passwordCheckInput.classList.add("input-error"); | ||||||||||||||||||||||||||||||||||||||
| if (!errorMessage) { | ||||||||||||||||||||||||||||||||||||||
| errorMessage = document.createElement("span"); | ||||||||||||||||||||||||||||||||||||||
| errorMessage.className = "error-message"; | ||||||||||||||||||||||||||||||||||||||
| errorMessage.style.cssText = "color: red; font-size: 14px; display: block; margin-top: 4px;"; | ||||||||||||||||||||||||||||||||||||||
| errorMessage.innerText = "비밀번호가 일치하지 않습니다."; | ||||||||||||||||||||||||||||||||||||||
| passwordCheckInput.closest(".input-group").appendChild(errorMessage); | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| errorMessage.innerText = "비밀번호가 일치하지 않습니다."; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| passwordCheckInput.classList.remove("input-error"); | ||||||||||||||||||||||||||||||||||||||
| if (errorMessage) errorMessage.remove(); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| checkFormValidity(); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // 비밀번호 보이게 하기 | ||||||||||||||||||||||||||||||||||||||
| const passwordWrappers = document.querySelectorAll(".password-wrapper"); | ||||||||||||||||||||||||||||||||||||||
| passwordWrappers.forEach(function (wrapper) { | ||||||||||||||||||||||||||||||||||||||
| const toggleButton = wrapper.querySelector("button"); | ||||||||||||||||||||||||||||||||||||||
| const input = wrapper.querySelector("input"); | ||||||||||||||||||||||||||||||||||||||
| if (toggleButton && input) { | ||||||||||||||||||||||||||||||||||||||
| toggleButton.addEventListener("click", function (e) { | ||||||||||||||||||||||||||||||||||||||
| e.preventDefault(); | ||||||||||||||||||||||||||||||||||||||
| input.type = input.type === "password" ? "text" : "password"; | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // 폼 제출 처리 | ||||||||||||||||||||||||||||||||||||||
| form.addEventListener("submit", function (e) { | ||||||||||||||||||||||||||||||||||||||
| e.preventDefault(); | ||||||||||||||||||||||||||||||||||||||
| if (button.disabled) return; | ||||||||||||||||||||||||||||||||||||||
| if (nicknameInput || passwordCheckInput) { | ||||||||||||||||||||||||||||||||||||||
| window.location.href = "login.html"; | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| window.location.href = "/items"; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+175
to
+183
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💊 제안
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
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.
💊 제안
아마 script 태그를 HTML의 하단에 배치하신 이유가 script가 문서의 렌더링을 막지 않도록 하기 위해서이실 것 같아요.
하지만, script 태그에 defer나 async 속성을 사용하면 이런 문제를 해결할 수 있기 때문에 반드시 하단에 배치할 필요는 없습니다!
또한 script 태그는 상단에 있는게 구조 파악에서도 유리하기 때문에 상단 head 태그에 두시는 것을 추천드려요~
script async
script defer
지금과 같은 경우 DOM을 조작하는 JS 이니 defer 속성을 추가하시면 되겠습니다~