import AbstractView from "../AbstractView.js"; import { client } from "../../index.js"; async function register() { let username = document.getElementById("username").value; let password = document.getElementById("password").value; let response = await client.accounts.create(username, password); let response_data = await response.json(); ["username", "user", "password"].forEach(error_field => { let error_display = document.getElementById(`error_${error_field}`); if (error_display != null) error_display.innerHTML = ""; }); Object.keys(response_data).forEach(error_field => { let error_display = document.getElementById(`error_${error_field}`); if (error_display != null) error_display.innerHTML = response_data[error_field]; }); } 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 getHtml() { return `
`; } }