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
This commit is contained in:
John McCambridge 2019-04-12 10:35:30 -05:00 committed by Asher
parent f7342ede69
commit db57aa229f
2 changed files with 26 additions and 21 deletions

View File

@ -7,22 +7,24 @@
</head> </head>
<body> <body>
<div class="login"> <form id="login-form">
<div class="back"> <- Back </div> <div class="login">
<h4 class="title">code-server</h4> <div class="back">
<h2 class="subtitle"> <- Back </div> <h4 class="title">code-server</h4>
Enter server password <h2 class="subtitle">
</h2> Enter server password
<div class="mdc-text-field"> </h2>
<input type="password" id="password" class="mdc-text-field__input" required> <div class="mdc-text-field">
<label class="mdc-floating-label" for="password">Password</label> <input type="password" id="password" class="mdc-text-field__input" required>
<div class="mdc-line-ripple"></div> <label class="mdc-floating-label" for="password">Password</label>
</div> <div class="mdc-line-ripple"></div>
<button id="submit" class="mdc-button mdc-button--unelevated"> </div>
<span class="mdc-button__label">Enter IDE</span> <button id="submit" class="mdc-button mdc-button--unelevated">
</button> <span class="mdc-button__label">Enter IDE</span>
<div id="error-display"></div> </button>
</div> <div id="error-display"></div>
</div>
</form>
</body> </body>
</html> </html>

View File

@ -20,11 +20,14 @@ window.addEventListener("message", (event) => {
}); });
const password = document.getElementById("password") as HTMLInputElement; const password = document.getElementById("password") as HTMLInputElement;
const submit = document.getElementById("submit") as HTMLButtonElement; const form = document.getElementById("login-form") as HTMLFormElement;
if (!submit) {
throw new Error("No submit button found"); if (!form) {
throw new Error("No password form found");
} }
submit.addEventListener("click", () => {
form.addEventListener("submit", (e) => {
e.preventDefault();
document.cookie = `password=${password.value}`; document.cookie = `password=${password.value}`;
location.reload(); location.reload();
}); });