-
Notifications
You must be signed in to change notification settings - Fork 35
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
[이형준]sprint4 #115
The head ref may contain hidden characters: "Basic-\uC774\uD615\uC900-sprint4"
[이형준]sprint4 #115
Changes from all commits
51d9c6a
a07419d
fba853c
8c19be8
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// validitiy checker (boolean) | ||
import { emailIsValid, nicknameIsValid, pwIsValid, pwRetypeIsValid } from './input.js'; | ||
|
||
const loginButton = document.querySelector('#login-button'); | ||
const signupButton = document.querySelector('#signup-button'); | ||
|
||
// every input is valid -> button disable=false | ||
export function buttonDisableChecker(event) { | ||
|
||
if(loginButton !== null) { | ||
if(emailIsValid && pwIsValid) { | ||
loginButton.disabled = false; | ||
} else { | ||
loginButton.disabled = true; | ||
} | ||
} | ||
|
||
if(signupButton !== null) { | ||
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. 이렇게 if 문 안에서 !== null 대신 truthy 값을 사용하여 조건을 단순화할수 있어요
|
||
if(emailIsValid && pwIsValid && nicknameIsValid && pwRetypeIsValid) { | ||
signupButton.disabled = false; | ||
} else { | ||
signupButton.disabled = true; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// password valid condition | ||
const PW_MIN_LENGTH = 8; | ||
|
||
// for button disable toggle | ||
export let emailIsValid = false; | ||
export let nicknameIsValid = false; | ||
export let pwIsValid = false; | ||
export let pwRetypeIsValid = false; | ||
|
||
// email validitiychecker | ||
export function emailInputCheck(event) { | ||
const target = event.target; | ||
const errorMessage = document.querySelector('#email-error-message'); | ||
|
||
if (target.value === "") { | ||
target.classList.add('error-input'); | ||
errorMessage.textContent = '이메일을 입력해주세요.'; | ||
emailIsValid = false; | ||
} | ||
// checkValidity() : true ("" or type match), false (different type) | ||
if (!target.checkValidity()) { | ||
target.classList.add('error-input'); | ||
errorMessage.textContent = '잘못된 이메일 형식입니다.'; | ||
emailIsValid = false; | ||
} | ||
if (target.checkValidity() && target.value !== "") { | ||
target.classList.remove('error-input'); | ||
errorMessage.textContent = ''; | ||
emailIsValid = true; | ||
} | ||
} | ||
Comment on lines
+11
to
+31
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.
이를 해결하기 위해, 아래 방법을 nicknameInputCheck, pwInputCheck, pwRetypeInputCheck 함수에 똑같이 적용해주시면 됩니다.
https://developer.mozilla.org/ko/docs/Web/API/Element/classList |
||
|
||
// nickname validitiychecker | ||
export function nicknameInputCheck(event) { | ||
const target = event.target; | ||
const errorMessage = document.querySelector('#nickname-error-message'); | ||
|
||
if (target.value === "") { | ||
target.classList.add('error-input'); | ||
errorMessage.textContent = '닉네임을 입력해주세요.'; | ||
nicknameIsValid = false; | ||
} else { | ||
target.classList.remove('error-input'); | ||
errorMessage.textContent = ''; | ||
nicknameIsValid = true; | ||
} | ||
} | ||
|
||
// password validitiychecker | ||
export function pwInputCheck(event) { | ||
const target = event.target; | ||
const errorMessage = document.querySelector('#password-error-message'); | ||
|
||
if (target.value.length === 0) { | ||
target.classList.add('error-input'); | ||
errorMessage.textContent = '비밀번호를 입력해주세요.'; | ||
pwIsValid = false; | ||
} | ||
if (target.value.length < PW_MIN_LENGTH && target.value.length > 0) { | ||
target.classList.add('error-input'); | ||
errorMessage.textContent = '비밀번호를 8자 이상 입력해주세요.'; | ||
pwIsValid = false; | ||
} | ||
if (target.value.length >= PW_MIN_LENGTH) { | ||
target.classList.remove('error-input'); | ||
errorMessage.textContent = ''; | ||
pwIsValid = true; | ||
} | ||
} | ||
|
||
// retype password validitiychecker | ||
export function pwRetypeInputCheck(event) { | ||
const target = event.target; | ||
const pwInput = document.querySelector('#password-input'); | ||
const errorMessage = document.querySelector('#password-retype-error-message'); | ||
|
||
if (target.value !== pwInput.value) { | ||
target.classList.add('error-input'); | ||
errorMessage.textContent = '비밀번호가 일치하지 않습니다.'; | ||
pwRetypeIsValid = false; | ||
} else { | ||
target.classList.remove('error-input'); | ||
errorMessage.textContent = ''; | ||
pwRetypeIsValid = true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { emailInputCheck,nicknameInputCheck, pwInputCheck, pwRetypeInputCheck } from './input.js'; | ||
import { buttonDisableChecker } from './button.js'; | ||
import { pwVisibleToggle } from './pw_visibility.js'; | ||
|
||
const emailInput = document.querySelector('#email-input'); | ||
const pwInput = document.querySelector('#password-input'); | ||
const pwRetypeInput = document.querySelector('#password-retype-input'); | ||
const nicknameInput = document.querySelector('#nickname-input'); | ||
|
||
const pwVisibleBtn = document.querySelector('#password-visibility-button'); | ||
const pwRetypeVisibleBtn = document.querySelector('#password-retype-visibility-button'); | ||
|
||
// login page event | ||
emailInput.addEventListener('focusout', emailInputCheck); | ||
pwInput.addEventListener('focusout', pwInputCheck); | ||
|
||
emailInput.addEventListener('focusout', buttonDisableChecker); | ||
pwInput.addEventListener('focusout', buttonDisableChecker); | ||
|
||
pwVisibleBtn.addEventListener('click', pwVisibleToggle); | ||
|
||
|
||
// additional event for signup page | ||
if (pwRetypeInput && nicknameInput) { | ||
nicknameInput.addEventListener('focusout', nicknameInputCheck); | ||
pwRetypeInput.addEventListener('focusout', pwRetypeInputCheck); | ||
|
||
nicknameInput.addEventListener('focusout', buttonDisableChecker); | ||
pwRetypeInput.addEventListener('focusout', buttonDisableChecker); | ||
|
||
pwRetypeVisibleBtn.addEventListener('click', pwVisibleToggle); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
let visibleMode = false; | ||
|
||
export function pwVisibleToggle(event) { | ||
const img = event.target; | ||
const input = img.parentElement.parentElement.firstElementChild; | ||
|
||
if (visibleMode) { | ||
img.src = "/images/btn_visibility_off.png"; | ||
input.type = "password"; | ||
visibleMode = false; | ||
} else { | ||
img.src = "/images/btn_visibility_on.png"; | ||
input.type = "text"; | ||
visibleMode = true; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
<link rel="stylesheet" href="/css/base/global.css" /> | ||
<link rel="stylesheet" href="/css/login.css" /> | ||
</head> | ||
|
||
<body> | ||
<header> | ||
<div class="logo-block"> | ||
|
@@ -26,30 +27,33 @@ | |
<div class="content"> | ||
<div> | ||
<h3>이메일</h3> | ||
<input type="email" | ||
<input type="email" id="email-input" | ||
placeholder="이메일을 입력해주세요" | ||
onfocus="this.placeholder=''" | ||
onblur="this.placeholder='이메일을 입력해주세요'" | ||
/> | ||
<p id="email-error-message" class="error-message"></p> | ||
</div> | ||
<div> | ||
<h3>비밀번호</h3> | ||
<div class="password-input"> | ||
<input type="password" | ||
<input type="password" id="password-input" | ||
placeholder="비밀번호를 입력해주세요" | ||
onfocus="this.placeholder=''" | ||
onblur="this.placeholder='비밀번호를 입력해주세요'" | ||
/> | ||
/> | ||
<a> | ||
<img | ||
class="visibility-button" | ||
src="/images/btn_visibility_off.png" | ||
alt="비밀번호 표시 옵션" | ||
id="password-visibility-button" | ||
class="visibility-button" | ||
src="/images/btn_visibility_off.png" | ||
alt="비밀번호 표시 옵션" | ||
/> | ||
</a> | ||
<p id="password-error-message" class="error-message"></p> | ||
</div> | ||
</div> | ||
<button>로그인</button> | ||
<button id="login-button" onclick="location.href='/pages/items'" disabled="true">로그인</button> | ||
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.
|
||
<div class="simple-login"> | ||
<p> | ||
간편 로그인하기 | ||
|
@@ -70,4 +74,8 @@ <h3>비밀번호</h3> | |
</div> | ||
</main> | ||
</body> | ||
|
||
<script type="module" src="/js/main.js"></script> | ||
<script type="module" src="/js/input.js"></script> | ||
<script type="module" src="/js/pw_visibility.js"></script> | ||
</html> |
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.
위 코드를 아래처럼 바꿀 수 있어요!
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.
추가적으로 함수를 작성했을 때, 타입스크립트를 아직 사용하지 않다보니 아래처럼 JSDoc을 통해 주석을 추가해주시면 좋아요.
관련 링크는 남겨놓을게요!
https://jsdoc.app/about-getting-started