-
Notifications
You must be signed in to change notification settings - Fork 20
[강석준] sprint4 #54
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-\uAC15\uC11D\uC900-sprint4"
[강석준] sprint4 #54
Changes from all commits
ec741da
c858253
8b413d6
b4ac738
59a8ed0
c3d3d9b
0996f0b
aef9ec9
84c9761
eeb2a31
e690554
b549406
6b0382f
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 | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,18 +1,112 @@ | ||||||||||||||||||||||||||||||||||||
| import { isEmpty } from "./utils.js"; | ||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||
| isEmpty, | ||||||||||||||||||||||||||||||||||||
| isEmailValid, | ||||||||||||||||||||||||||||||||||||
| isPwdValid, | ||||||||||||||||||||||||||||||||||||
| applyClass, | ||||||||||||||||||||||||||||||||||||
| removeClass, | ||||||||||||||||||||||||||||||||||||
| } from "./utils.js"; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const ERROR_EMAIL_EMPTY = "이메일을 입력해주세요."; | ||||||||||||||||||||||||||||||||||||
| const ERROR_EMAIL_PATTERN = "잘못된 이메일 형식입니다."; | ||||||||||||||||||||||||||||||||||||
| const ERROR_PASSWORD_EMPTY = "비밀번호를 입력해주세요."; | ||||||||||||||||||||||||||||||||||||
| const ERROR_PASSWORD_PATTERN = "비밀번호를 8자 이상 입력해주세요."; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+12
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 IMG_VISIBLE_ON = "../assets/ic_visibility_on.svg"; | ||||||||||||||||||||||||||||||||||||
| const IMG_VISIBLE_OFF = "../assets/ic_visibility_off.svg"; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const formInputWrappers = document.querySelectorAll( | ||||||||||||||||||||||||||||||||||||
| ".form__field-input-wrapper" | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
| const formInputs = document.querySelectorAll(".form__field-input"); | ||||||||||||||||||||||||||||||||||||
| const submitButton = document.querySelector(".form__submit-button--disabled"); | ||||||||||||||||||||||||||||||||||||
| const submitButton = document.querySelector(".form__submit-button"); | ||||||||||||||||||||||||||||||||||||
| const emailInput = document.querySelector("#email"); | ||||||||||||||||||||||||||||||||||||
| const emailInputWrapper = document.querySelector( | ||||||||||||||||||||||||||||||||||||
| ".form__field-input-wrapper--email" | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
| const emailMsgContainer = document.querySelector(".form__msg-container--email"); | ||||||||||||||||||||||||||||||||||||
| const pwdInput = document.querySelector("#password"); | ||||||||||||||||||||||||||||||||||||
| const pwdInputWrapper = document.querySelector( | ||||||||||||||||||||||||||||||||||||
| ".form__field-input-wrapper--password" | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
| const pwdMsgContainer = document.querySelector( | ||||||||||||||||||||||||||||||||||||
| ".form__msg-container--password" | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const pwdVisiblityButton = document.querySelector( | ||||||||||||||||||||||||||||||||||||
| ".form__field-button.form__field-button--password" | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
| const pwdVisiblityButtonImg = document.querySelector( | ||||||||||||||||||||||||||||||||||||
| ".form__field-image.form__field-image--password" | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const handleInputFocusin = () => { | ||||||||||||||||||||||||||||||||||||
| submitButton.disabled = true; | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| formInputs.forEach((inputNode) => | ||||||||||||||||||||||||||||||||||||
| inputNode.addEventListener("focusin", handleInputFocusin) | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| export const isFormValid = () => { | ||||||||||||||||||||||||||||||||||||
| const isInputsEmpty = Array.from(formInputs).some((input) => | ||||||||||||||||||||||||||||||||||||
| isEmpty(input.value) | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
| const isInputsValid = Array.from(formInputWrappers).every( | ||||||||||||||||||||||||||||||||||||
| (input) => !input.classList.contains("error") | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return !isInputsEmpty && isInputsValid; | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const updateSubmitButton = () => { | ||||||||||||||||||||||||||||||||||||
| const isFormFilled = Array.from(formInputs) | ||||||||||||||||||||||||||||||||||||
| .map((input) => input.value) | ||||||||||||||||||||||||||||||||||||
| .every((string) => !isEmpty(string)); | ||||||||||||||||||||||||||||||||||||
| const handleEmailFocusout = (e) => { | ||||||||||||||||||||||||||||||||||||
| const email = e.target.value; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| submitButton.disabled = !isFormFilled; | ||||||||||||||||||||||||||||||||||||
| if (!isEmailValid(email)) { | ||||||||||||||||||||||||||||||||||||
| applyClass(emailInputWrapper, "error"); | ||||||||||||||||||||||||||||||||||||
| emailMsgContainer.textContent = isEmpty(email) | ||||||||||||||||||||||||||||||||||||
| ? ERROR_EMAIL_EMPTY | ||||||||||||||||||||||||||||||||||||
| : ERROR_EMAIL_PATTERN; | ||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||
| removeClass(emailInputWrapper, "error"); | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+65
to
+71
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.
|
||||||||||||||||||||||||||||||||||||
| emailMsgContainer.textContent = ""; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| submitButton.disabled = !isFormValid(); | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+61
to
+76
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 handlePwdFocusout = (e) => { | ||||||||||||||||||||||||||||||||||||
| const pwd = e.target.value; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (!isPwdValid(pwd)) { | ||||||||||||||||||||||||||||||||||||
| applyClass(pwdInputWrapper, "error"); | ||||||||||||||||||||||||||||||||||||
| pwdMsgContainer.textContent = isEmpty(pwd) | ||||||||||||||||||||||||||||||||||||
| ? ERROR_PASSWORD_EMPTY | ||||||||||||||||||||||||||||||||||||
| : ERROR_PASSWORD_PATTERN; | ||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||
| removeClass(pwdInputWrapper, "error"); | ||||||||||||||||||||||||||||||||||||
| pwdMsgContainer.textContent = ""; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| submitButton.disabled = !isFormValid(); | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| formInputs.forEach((input) => { | ||||||||||||||||||||||||||||||||||||
| input.addEventListener("input", updateSubmitButton); | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
| emailInput.addEventListener("focusout", handleEmailFocusout); | ||||||||||||||||||||||||||||||||||||
| pwdInput.addEventListener("focusout", handlePwdFocusout); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| export const createVisibilityToggleHandler = (input, image) => { | ||||||||||||||||||||||||||||||||||||
| let visible = false; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return function onClickToggleButton() { | ||||||||||||||||||||||||||||||||||||
| visible = !visible; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| input.type = visible ? "text" : "password"; | ||||||||||||||||||||||||||||||||||||
| image.src = visible ? IMG_VISIBLE_ON : IMG_VISIBLE_OFF; | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+99
to
+106
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
|
||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| updateSubmitButton(); | ||||||||||||||||||||||||||||||||||||
| pwdVisiblityButton.addEventListener( | ||||||||||||||||||||||||||||||||||||
| "click", | ||||||||||||||||||||||||||||||||||||
| createVisibilityToggleHandler(pwdInput, pwdVisiblityButtonImg) | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
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.
굿굿 ~!
global.css를 후순위로 두셨군요 !global.css를 후순위로 두셨군요 ! 이제 초기화를 한 후 전역적인 스타일을 적용되어 의도하신 우선순위대로 동작할 것으로 기대됩니다 !