From db57aa229fb62bac87b6b941df1a92e822caf257 Mon Sep 17 00:00:00 2001 From: John McCambridge Date: Fri, 12 Apr 2019 10:35:30 -0500 Subject: [PATCH] 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 --- packages/app/browser/src/app.html | 34 ++++++++++++++++--------------- packages/app/browser/src/app.ts | 13 +++++++----- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/packages/app/browser/src/app.html b/packages/app/browser/src/app.html index 99e23733..dadd6d54 100644 --- a/packages/app/browser/src/app.html +++ b/packages/app/browser/src/app.html @@ -7,22 +7,24 @@ -
-
<- Back
-

code-server

-

- Enter server password -

-
- - -
-
- -
-
+
+ +
\ No newline at end of file diff --git a/packages/app/browser/src/app.ts b/packages/app/browser/src/app.ts index ddb35e7e..9e377845 100644 --- a/packages/app/browser/src/app.ts +++ b/packages/app/browser/src/app.ts @@ -20,11 +20,14 @@ window.addEventListener("message", (event) => { }); const password = document.getElementById("password") as HTMLInputElement; -const submit = document.getElementById("submit") as HTMLButtonElement; -if (!submit) { - throw new Error("No submit button found"); +const form = document.getElementById("login-form") as HTMLFormElement; + +if (!form) { + throw new Error("No password form found"); } -submit.addEventListener("click", () => { + +form.addEventListener("submit", (e) => { + e.preventDefault(); document.cookie = `password=${password.value}`; location.reload(); }); @@ -38,4 +41,4 @@ const errorDisplay = document.getElementById("error-display") as HTMLDivElement; if (document.referrer === document.location.href && matches) { errorDisplay.innerText = "Password is incorrect!"; -} \ No newline at end of file +}