-
Notifications
You must be signed in to change notification settings - Fork 39
[손수진] Sprint4 #143
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-\uC190\uC218\uC9C4-sprint4"
[손수진] Sprint4 #143
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
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,25 @@ | ||
| import { | ||
| buttonDeactivate, | ||
| requireContent, | ||
| buttonActivate, | ||
| checkPassword, | ||
| visibleIconToggle, | ||
| } from "./loginFunctions.js"; | ||
| const primary_btn = document.querySelector(".primary_btn"); | ||
| buttonDeactivate(primary_btn); | ||
|
|
||
| document.getElementById("email").addEventListener("focusout", requireContent); | ||
| document.getElementById("password").addEventListener("focusout", requireContent); | ||
| document.getElementById("nickname")?.addEventListener("focusout", requireContent); | ||
| document.getElementById("password_check")?.addEventListener("focusout", (e) => { | ||
| checkPassword(e); | ||
| buttonActivate(e); | ||
| }); | ||
| primary_btn.addEventListener("click", (e) => { | ||
| e.preventDefault(); | ||
| console.log("Button clicked! Moving to ./login.html"); | ||
| window.location.href = "./login.html"; | ||
| }); | ||
| document.querySelectorAll(".visible_icon").forEach((item) => { | ||
| item.addEventListener("click", visibleIconToggle); | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,103 @@ | ||||||||||||||||||||||||||||||||||
| const ERRORMESSAGE = { | ||||||||||||||||||||||||||||||||||
| wrongEmail: "잘못된 이메일 형식입니다", | ||||||||||||||||||||||||||||||||||
| wrongPassword: "비밀번호를 8자 이상 입력해주세요", | ||||||||||||||||||||||||||||||||||
| emailIsEmpty: "이메일을 입력해주세요", | ||||||||||||||||||||||||||||||||||
| passwordIsEmpty: "비밀번호를 입력해주세요", | ||||||||||||||||||||||||||||||||||
| nicknameIsEmpty: "닉네임을 입력해주세요", | ||||||||||||||||||||||||||||||||||
| passwordIsNotSame: "비밀번호가 일치하지 않습니다.", | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+8
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 requireContent = (e) => { | ||||||||||||||||||||||||||||||||||
|
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. 💊 제안 const checkEmailValid = (input) => {
const emailRegex =
/^[a-zA-Z0-9]+([._-][a-zA-Z0-9]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})+$/;
if (emailRegex.test(input.value)) return ERRORMESSAGE.wrongEmail;
return ERRORMESSAGE.emailIsEmpty;
};
const checkPasswordValid = () => {
if (input.value.length < 8) return ERRORMESSAGE.wrongPassword;
return ERRORMESSAGE.passwordIsEmpty;
};
const checkNicknameValid = (input) => {
if (input.value.trim() === "") return ERRORMESSAGE.nicknameIsEmpty;
};
const requireContent = (e) => {
const target = e.target;
switch (target.id) {
case "email":
createNewMessage(checkEmailValid(target), target);
break;
case "password":
createNewMessage(checkPasswordValid(target), target);
document.querySelector(".visible_icon").style = "bottom: 6.9rem;";
break;
case "nickname":
createNewMessage(checkNicknameValid(target), target);
break;
}
if (e.target.nextElementSibling?.tagName == "P") {
e.target.style = "border: none";
e.target.nextElementSibling.remove();
document.querySelector(".visible_icon").style = "bottom: 1.4rem;";
}
};내부로직을 제가 다 잘 파악한 것인지 모르겠으니 위의 코드는 방향성만 참고해주세요~ |
||||||||||||||||||||||||||||||||||
| console.log("requireContent called for:", e.target.id); | ||||||||||||||||||||||||||||||||||
| let content = e.target.value; | ||||||||||||||||||||||||||||||||||
|
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
|
||||||||||||||||||||||||||||||||||
| let emailRegex = /^[a-zA-Z0-9]+([._-][a-zA-Z0-9]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})+$/; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (content) { | ||||||||||||||||||||||||||||||||||
| if (emailRegex.test(content) === false && e.target.id == "email") { | ||||||||||||||||||||||||||||||||||
| createNewMessage(ERRORMESSAGE.wrongEmail, e.target); | ||||||||||||||||||||||||||||||||||
| } else if (e.target.nextElementSibling?.tagName == "P") { | ||||||||||||||||||||||||||||||||||
| e.target.style = "border: none"; | ||||||||||||||||||||||||||||||||||
| e.target.nextElementSibling.remove(); | ||||||||||||||||||||||||||||||||||
| document.querySelector(".visible_icon").style = "bottom: 1.4rem;"; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (e.target.id == "password" && content.length < 8) { | ||||||||||||||||||||||||||||||||||
| createNewMessage(ERRORMESSAGE.wrongPassword, e.target); | ||||||||||||||||||||||||||||||||||
| document.querySelector(".visible_icon").style = "bottom: 6.9rem;"; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||
| let messageContent; | ||||||||||||||||||||||||||||||||||
| switch (e.target.id) { | ||||||||||||||||||||||||||||||||||
| case "email": | ||||||||||||||||||||||||||||||||||
| messageContent = ERRORMESSAGE.emailIsEmpty; | ||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||
| case "password": | ||||||||||||||||||||||||||||||||||
| messageContent = ERRORMESSAGE.passwordIsEmpty; | ||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||
| case "nickname": | ||||||||||||||||||||||||||||||||||
| messageContent = ERRORMESSAGE.nicknameIsEmpty; | ||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| createNewMessage(messageContent, e.target); | ||||||||||||||||||||||||||||||||||
| document.querySelector(".visible_icon").style = "bottom: 6.9rem;"; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const createNewMessage = (messageContent, target) => { | ||||||||||||||||||||||||||||||||||
|
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
|
||||||||||||||||||||||||||||||||||
| target.style = "border: 1px solid red"; | ||||||||||||||||||||||||||||||||||
| if (target.nextElementSibling?.tagName == "P") { | ||||||||||||||||||||||||||||||||||
| target.nextElementSibling.innerText = messageContent; | ||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||
| let pTag = document.createElement("p"); | ||||||||||||||||||||||||||||||||||
| pTag.textContent = messageContent; | ||||||||||||||||||||||||||||||||||
| pTag.classList.add("plzInputText"); | ||||||||||||||||||||||||||||||||||
| target.after(pTag); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const buttonDeactivate = (tag) => { | ||||||||||||||||||||||||||||||||||
| tag.disabled = true; | ||||||||||||||||||||||||||||||||||
| tag.style = "background-color: var(--gray400)"; | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const buttonActivate = (e) => { | ||||||||||||||||||||||||||||||||||
| const nodeList = document.getElementsByClassName("plzInputText"); | ||||||||||||||||||||||||||||||||||
| const inputs = [...document.getElementsByTagName("input")]; | ||||||||||||||||||||||||||||||||||
| let inputIsEmpty = inputs.every((input) => input.value && input.value.trim() !== ""); | ||||||||||||||||||||||||||||||||||
| if (nodeList.length !== 0 && !inputIsEmpty) { | ||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||
| let submit_btn = document.querySelector(".primary_btn"); | ||||||||||||||||||||||||||||||||||
| submit_btn.disabled = false; | ||||||||||||||||||||||||||||||||||
| submit_btn.style = "background-color: var(--blue)"; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const checkPassword = (e) => { | ||||||||||||||||||||||||||||||||||
| let password = document.getElementById("password"); | ||||||||||||||||||||||||||||||||||
| let passwordCheck = document.getElementById("password_check"); | ||||||||||||||||||||||||||||||||||
| if (password && passwordCheck) { | ||||||||||||||||||||||||||||||||||
| if (password.value !== passwordCheck.value) { | ||||||||||||||||||||||||||||||||||
| createNewMessage(ERRORMESSAGE.passwordIsNotSame, e.target); | ||||||||||||||||||||||||||||||||||
| e.target.previousElementSibling.style = "bottom: 6.9rem;"; | ||||||||||||||||||||||||||||||||||
| } else if (e.target.nextElementSibling?.tagName === "P") { | ||||||||||||||||||||||||||||||||||
| e.target.style = "border: none"; | ||||||||||||||||||||||||||||||||||
| e.target.nextElementSibling.remove(); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const visibleIconToggle = (e) => { | ||||||||||||||||||||||||||||||||||
| e.target.classList.toggle("passwordIsVisible"); | ||||||||||||||||||||||||||||||||||
| if (e.target.nextElementSibling.type == "password") { | ||||||||||||||||||||||||||||||||||
|
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. 💊 제안 |
||||||||||||||||||||||||||||||||||
| e.target.nextElementSibling.type = "text"; | ||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||
| e.target.nextElementSibling.type = "password"; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
| export { | ||||||||||||||||||||||||||||||||||
| requireContent, | ||||||||||||||||||||||||||||||||||
| createNewMessage, | ||||||||||||||||||||||||||||||||||
| buttonDeactivate, | ||||||||||||||||||||||||||||||||||
| buttonActivate, | ||||||||||||||||||||||||||||||||||
| checkPassword, | ||||||||||||||||||||||||||||||||||
| visibleIconToggle, | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
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 태그는 상단에 있는게 구조 파악측면에서 유리하다고 생각해서 큰 이유가 없다면 상단 head 태그에 두시는 것을 추천드려요~
특히 타입이 모듈인 스크립트는 defer 속성을 자동으로 가지기 때문에 따로 하단에 배치하실 이유가 없습니다~