use post init to onclick
This commit is contained in:
parent
d490208ffa
commit
3f3ab52a09
@ -1,5 +1,5 @@
|
||||
import AbstractView from "../AbstractView.js";
|
||||
import { client } from "../../index.js";
|
||||
import { client, navigateTo } from "../../index.js";
|
||||
|
||||
async function login()
|
||||
{
|
||||
@ -8,7 +8,13 @@ async function login()
|
||||
|
||||
let response = await client.login(username, password);
|
||||
let response_data = await response.json();
|
||||
|
||||
|
||||
if (response_data == "user connected")
|
||||
{
|
||||
navigateTo("/home");
|
||||
return;
|
||||
}
|
||||
|
||||
["username", "user", "password"].forEach(error_field => {
|
||||
let error_display = document.getElementById(`error_${error_field}`);
|
||||
if (error_display != null)
|
||||
@ -26,11 +32,11 @@ export default class extends AbstractView {
|
||||
constructor(params) {
|
||||
super(params);
|
||||
this.setTitle("Login");
|
||||
document.body.addEventListener("click", e => {
|
||||
e.preventDefault();
|
||||
if (e.target.type == "button")
|
||||
login();
|
||||
});
|
||||
}
|
||||
|
||||
async postInit()
|
||||
{
|
||||
document.getElementById("button").onclick = login;
|
||||
}
|
||||
|
||||
async getHtml() {
|
||||
@ -42,7 +48,7 @@ export default class extends AbstractView {
|
||||
<span id="error_username"></span>
|
||||
<input type="password" id="password" placeholder="password">
|
||||
<span id="error_password"></span>
|
||||
<input type="button" value="login">
|
||||
<input type="button" value="login" id="button">
|
||||
<span id="error_user"></span>
|
||||
<a href="/register" class="nav__link" data-link>Register</a>
|
||||
</div>
|
||||
|
@ -26,11 +26,11 @@ export default class extends AbstractView {
|
||||
constructor(params) {
|
||||
super(params);
|
||||
this.setTitle("register");
|
||||
document.body.addEventListener("click", e => {
|
||||
e.preventDefault();
|
||||
if (e.target.type == "button")
|
||||
register();
|
||||
});
|
||||
}
|
||||
|
||||
async postInit()
|
||||
{
|
||||
document.getElementById("button").onclick = register;
|
||||
}
|
||||
|
||||
async getHtml() {
|
||||
@ -42,7 +42,7 @@ export default class extends AbstractView {
|
||||
<span id="error_username"></span>
|
||||
<input type="password" id="password" placeholder="password">
|
||||
<span id="error_password"></span>
|
||||
<input type="button" value="register">
|
||||
<input type="button" value="register" id="button">
|
||||
<span id="error_user"></span>
|
||||
<a href="/login" class="nav__link" data-link>Login</a>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user