|
| 1 | +import Alert from "../components/alert.js"; |
1 | 2 |
|
2 | 3 | export default function Signup() { |
3 | | - |
4 | | - const existing = document.querySelector('link[data-signup-style]'); |
| 4 | + const existing = document.querySelector("link[data-signup-style]"); |
5 | 5 | if (!existing) { |
6 | | - const link = document.createElement("link"); |
7 | | - link.rel = "stylesheet"; |
8 | | - link.href = "/css/signup.css"; |
9 | | - link.setAttribute("data-signup-style", "true"); |
10 | | - document.head.appendChild(link); |
| 6 | + const link = document.createElement("link"); |
| 7 | + link.rel = "stylesheet"; |
| 8 | + link.href = "/css/signup.css"; |
| 9 | + link.setAttribute("data-signup-style", "true"); |
| 10 | + document.head.appendChild(link); |
11 | 11 | } |
12 | 12 |
|
13 | 13 | return /*HTML*/ ` |
@@ -50,29 +50,48 @@ export default function Signup() { |
50 | 50 |
|
51 | 51 | <button type="submit" class="btn">Submit</button> |
52 | 52 | </form> |
53 | | -
|
| 53 | + |
| 54 | + <div id="alert-container"> |
54 | 55 | <!-- Alert-boks LATER --> |
| 56 | + </div> |
55 | 57 | </div> |
56 | 58 | `; |
57 | | - |
58 | 59 | } |
59 | 60 |
|
60 | 61 | export function initSignupForm() { |
61 | 62 | const form = document.querySelector("#signup-form"); |
62 | 63 | if (!form) return; |
63 | 64 |
|
64 | | - form.addEventListener("submit", e => { |
| 65 | + form.addEventListener("submit", (e) => { |
65 | 66 | e.preventDefault(); |
66 | 67 |
|
67 | | - const password = document.querySelector("#password").value; |
68 | | - const confirm = document.querySelector("#confirm-password").value; |
| 68 | + const passwordInput = form.querySelector("#password"); |
| 69 | + const confirmInput = form.querySelector("#confirm-password"); |
| 70 | + if (!passwordInput || !confirmInput) return; |
| 71 | + |
| 72 | + const password = passwordInput.value; |
| 73 | + const confirm = confirmInput.value; |
| 74 | + |
| 75 | + const alertContainer = document.querySelector("#alert-container"); |
| 76 | + if (!alertContainer) return; |
| 77 | + |
| 78 | + alertContainer.innerHTML = ""; |
69 | 79 |
|
70 | | - /* -------- Extra function ----------- |
71 | 80 | if (password !== confirm) { |
72 | | - alert("Passwords do not match"); |
| 81 | + alertContainer.innerHTML = Alert( |
| 82 | + "failed", |
| 83 | + "Failed Sign Up!", |
| 84 | + "Passwords do not match!" |
| 85 | + ); |
| 86 | + |
| 87 | + const closeButton = alertContainer.querySelector(".alert-close"); |
| 88 | + if (closeButton) { |
| 89 | + closeButton.addEventListener("click", () => { |
| 90 | + alertContainer.innerHTML = ""; |
| 91 | + }); |
| 92 | + } |
| 93 | + |
73 | 94 | return; |
74 | 95 | } |
75 | | -
|
76 | | - alert("Form passed validation ✅");*/ |
77 | 96 | }); |
78 | 97 | } |
0 commit comments