diff --git a/base.css b/base.css index 069cd575..a1b48259 100644 --- a/base.css +++ b/base.css @@ -37,9 +37,6 @@ html { font-size: 1.6rem; font-weight: 400; } -.letter-sp-04 { - letter-spacing: .4rem; -} /* buttons */ @@ -59,6 +56,8 @@ button:active { } button.inactive { background: var(--color-gray-400); + pointer-events: none; + cursor: default; } button.large { width: 100%; diff --git a/index.html b/index.html index e8ba5d36..46842112 100644 --- a/index.html +++ b/index.html @@ -6,13 +6,13 @@ - + - + 판다마켓
-
+
- +
- +
간편 로그인하기 @@ -43,5 +43,7 @@ 회원가입
+ + diff --git a/passwordToggle.js b/passwordToggle.js new file mode 100644 index 00000000..a9d4a389 --- /dev/null +++ b/passwordToggle.js @@ -0,0 +1,10 @@ +function togglePassword(e) { + const input = e.target.parentElement.querySelector("input"); + const isOpened = input.type === "text"; + input.type = isOpened ? "password" : "text"; + e.target.classList.toggle("visible", !isOpened); +} + +const btns = document.querySelectorAll(".btn-show").forEach((btn) => { + btn.addEventListener("click", (e) => togglePassword(e)); +}); diff --git a/signup.html b/signup.html index 1e9e19c0..4cb64bf8 100644 --- a/signup.html +++ b/signup.html @@ -15,26 +15,26 @@
-
+
- - + +
- - + +
-
- - +
+ +
- +
+ + diff --git a/validation.js b/validation.js new file mode 100644 index 00000000..c34bbf8f --- /dev/null +++ b/validation.js @@ -0,0 +1,56 @@ +function validateInput(el, label) { + const { validity } = el; + if (!validity.valid) { + if (validity.valueMissing) return `${label}을 입력해주세요`; + if (validity.typeMismatch) return "잘못된 이메일 형식입니다"; + if (validity.tooShort) return "비밀번호를 8자 이상 입력해주세요"; + if (validity.customError) return el.validationMessage; + } + return ""; +} + +function setPasswordValidity() { + const [pw, pwCheck] = document.querySelectorAll("input[id^=signup_password]"); + if (pw.value !== pwCheck.value) { + pwCheck.setCustomValidity("비밀번호가 일치하지 않습니다"); + } else { + pwCheck.setCustomValidity(""); + } +} + +function showValidMessage(el) { + const inputEl = el; + const parentEl = inputEl.parentElement; + const targetLabel = parentEl.firstElementChild.textContent; + + let p = parentEl.querySelector("p"); + let errMsg = validateInput(inputEl, targetLabel); + + if (errMsg) { + if (!p) { + p = document.createElement("p"); + p.classList.add("invalid-input"); + inputEl.after(p); + } + p.textContent = errMsg; + } else { + p && p.remove(); + } +} + +function checkBtnState(form, inputs) { + form.id === "signup_form" && setPasswordValidity(); + const btn = form.querySelector("button.large"); + const isValid = [...inputs].every((input) => input.validity.valid); + btn.classList.toggle("inactive", !isValid); +} + +const form = document.querySelector("form"); +const inputs = form.querySelectorAll("input"); +inputs.forEach((inputEl) => { + inputEl.addEventListener("input", () => { + checkBtnState(form, inputs); + inputEl.id === "signup_password_check" && showValidMessage(inputEl); + }); + inputEl.addEventListener("focusout", (e) => showValidMessage(e.target)); +});