-
Notifications
You must be signed in to change notification settings - Fork 39
[김정우] Sprint4 #169
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-\uAE40\uC815\uC6B0-sprint1"
[김정우] Sprint4 #169
Changes from all commits
fa57257
fd0b13e
9c69811
7caca40
ecaf141
944ee3a
bb30a64
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,81 @@ | ||||||||||||||||||||||
| const emailInput = document.getElementById("userName"); | ||||||||||||||||||||||
| const passwordInput = document.getElementById("userPassword"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const errorMessage = document.getElementById("error-message"); | ||||||||||||||||||||||
| const errorPassword = document.getElementById("error-password"); | ||||||||||||||||||||||
|
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. 💊 제안
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const loginBtn = document.getElementById("loginBtn"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| document.addEventListener("DOMContentLoaded", () => { | ||||||||||||||||||||||
| emailInput.addEventListener("input", () => { | ||||||||||||||||||||||
| if (emailInput.value !== "" && emailInput.value.includes("@")) { | ||||||||||||||||||||||
|
Comment on lines
+10
to
+11
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
|
||||||||||||||||||||||
| emailInput.classList.remove("error"); | ||||||||||||||||||||||
| errorMessage.textContent = ""; | ||||||||||||||||||||||
| errorMessage.style.display = "none"; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| updateButtonState(); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| passwordInput.addEventListener("input", () => { | ||||||||||||||||||||||
| if (passwordInput.value.length >= 8) { | ||||||||||||||||||||||
| passwordInput.classList.remove("error"); | ||||||||||||||||||||||
| errorPassword.textContent = ""; | ||||||||||||||||||||||
| errorPassword.style.display = "none"; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| updateButtonState(); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| emailInput.addEventListener("focusout", () => { | ||||||||||||||||||||||
| if (emailInput.value === "") { | ||||||||||||||||||||||
| emailInput.classList.add("error"); | ||||||||||||||||||||||
| errorMessage.textContent = "잘못된 이메일입니다."; | ||||||||||||||||||||||
| errorMessage.style.display = "block"; | ||||||||||||||||||||||
| } else if (!emailInput.value.includes("@")) { | ||||||||||||||||||||||
| emailInput.classList.add("error"); | ||||||||||||||||||||||
| errorMessage.textContent = "잘못된 이메일 형식입니다."; | ||||||||||||||||||||||
| errorMessage.style.display = "block"; | ||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| emailInput.classList.remove("error"); | ||||||||||||||||||||||
| errorMessage.textContent = ""; | ||||||||||||||||||||||
| errorMessage.style.display = "none"; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| updateButtonState(); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| passwordInput.addEventListener("focusout", () => { | ||||||||||||||||||||||
| if (passwordInput.value === "") { | ||||||||||||||||||||||
| passwordInput.classList.add("error"); | ||||||||||||||||||||||
| errorPassword.textContent = "비밀번호를 입력해주세요"; | ||||||||||||||||||||||
| errorPassword.style.display = "block"; | ||||||||||||||||||||||
| } else if (passwordInput.value.length < 8) { | ||||||||||||||||||||||
| passwordInput.classList.add("error"); | ||||||||||||||||||||||
| errorPassword.textContent = "비밀번호를 8자 이상 입력해주세요."; | ||||||||||||||||||||||
| errorPassword.style.display = "block"; | ||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| passwordInput.classList.remove("error"); | ||||||||||||||||||||||
| errorPassword.textContent = ""; | ||||||||||||||||||||||
| errorPassword.style.display = "none"; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| updateButtonState(); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| loginBtn.addEventListener("click", function (e) { | ||||||||||||||||||||||
| e.preventDefault(); | ||||||||||||||||||||||
| if (!loginBtn.disabled) { | ||||||||||||||||||||||
| window.location.href = "/item"; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
Comment on lines
+62
to
+67
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
|
||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| function updateButtonState() { | ||||||||||||||||||||||
| const hasError = | ||||||||||||||||||||||
| emailInput.classList.contains("error") || | ||||||||||||||||||||||
| passwordInput.classList.contains("error"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const isFilled = emailInput.value !== "" && passwordInput.value.length >= 8; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const shouldEnable = !hasError && isFilled; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| loginBtn.disabled = !shouldEnable; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| //비활성화 시킨 버튼 어떻게 활성화 시킬지 모르겠어서 updateButtonState()부분은 챗GPT의 도움을 받았습니다. 코드 보면서 더 공부하겠습니다. | ||||||||||||||||||||||
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 속성을 추가하시면 되겠습니다~