Skip to content

Commit 785e2b9

Browse files
author
John McCambridge
committed
Handle form submit action
1 parent f7c91f5 commit 785e2b9

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/app/browser/src/app.html

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
</head>
88

99
<body>
10-
<form action="javascript:history.go(0)">
10+
<form id="login-form">
1111
<div class="login">
1212
<div class="back">
1313
<- Back </div> <h4 class="title">code-server</h4>
1414
<h2 class="subtitle">
1515
Enter server password
1616
</h2>
17-
<form>
1817
<div class="mdc-text-field">
1918
<input type="password" id="password" class="mdc-text-field__input" required>
2019
<label class="mdc-floating-label" for="password">Password</label>
@@ -23,7 +22,6 @@ <h2 class="subtitle">
2322
<button id="submit" class="mdc-button mdc-button--unelevated">
2423
<span class="mdc-button__label">Enter IDE</span>
2524
</button>
26-
</form>
2725
<div id="error-display"></div>
2826
</div>
2927
</form>

packages/app/browser/src/app.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ window.addEventListener("message", (event) => {
2121

2222
const password = document.getElementById("password") as HTMLInputElement;
2323
const submit = document.getElementById("submit") as HTMLButtonElement;
24+
const form = document.getElementById("login-form") as HTMLFormElement;
25+
2426
if (!submit) {
2527
throw new Error("No submit button found");
2628
}
27-
submit.addEventListener("click", () => {
29+
30+
form.addEventListener("submit", (e) => {
31+
e.preventDefault();
2832
document.cookie = `password=${password.value}`;
2933
location.reload();
3034
});

0 commit comments

Comments
 (0)