Skip to content

Commit 1226578

Browse files
nol166code-asher
authored andcommitted
Allow use of the enter key for password input for code-server (#479)
* Allow use of the enter key for password input for code-server * Remove function, make html form * Remove function and create html form * Handle form submit action * Remove button listener * Check if form exists
1 parent 9295652 commit 1226578

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

packages/app/browser/src/app.html

+18-16
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@
77
</head>
88

99
<body>
10-
<div class="login">
11-
<div class="back"> <- Back </div>
12-
<h4 class="title">code-server</h4>
13-
<h2 class="subtitle">
14-
Enter server password
15-
</h2>
16-
<div class="mdc-text-field">
17-
<input type="password" id="password" class="mdc-text-field__input" required>
18-
<label class="mdc-floating-label" for="password">Password</label>
19-
<div class="mdc-line-ripple"></div>
20-
</div>
21-
<button id="submit" class="mdc-button mdc-button--unelevated">
22-
<span class="mdc-button__label">Enter IDE</span>
23-
</button>
24-
<div id="error-display"></div>
25-
</div>
10+
<form id="login-form">
11+
<div class="login">
12+
<div class="back">
13+
<- Back </div> <h4 class="title">code-server</h4>
14+
<h2 class="subtitle">
15+
Enter server password
16+
</h2>
17+
<div class="mdc-text-field">
18+
<input type="password" id="password" class="mdc-text-field__input" required>
19+
<label class="mdc-floating-label" for="password">Password</label>
20+
<div class="mdc-line-ripple"></div>
21+
</div>
22+
<button id="submit" class="mdc-button mdc-button--unelevated">
23+
<span class="mdc-button__label">Enter IDE</span>
24+
</button>
25+
<div id="error-display"></div>
26+
</div>
27+
</form>
2628
</body>
2729

2830
</html>

packages/app/browser/src/app.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ window.addEventListener("message", (event) => {
2020
});
2121

2222
const password = document.getElementById("password") as HTMLInputElement;
23-
const submit = document.getElementById("submit") as HTMLButtonElement;
24-
if (!submit) {
25-
throw new Error("No submit button found");
23+
const form = document.getElementById("login-form") as HTMLFormElement;
24+
25+
if (!form) {
26+
throw new Error("No password form found");
2627
}
27-
submit.addEventListener("click", () => {
28+
29+
form.addEventListener("submit", (e) => {
30+
e.preventDefault();
2831
document.cookie = `password=${password.value}`;
2932
location.reload();
3033
});
@@ -38,4 +41,4 @@ const errorDisplay = document.getElementById("error-display") as HTMLDivElement;
3841

3942
if (document.referrer === document.location.href && matches) {
4043
errorDisplay.innerText = "Password is incorrect!";
41-
}
44+
}

0 commit comments

Comments
 (0)