Replace 'onload' with an event listener
This commit is contained in:
parent
ea3339d413
commit
42ff4cac1a
2 changed files with 5 additions and 5 deletions
|
@ -52,7 +52,7 @@
|
||||||
</p>
|
</p>
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
<form action="/api/toot" method="POST" onsubmit="onFormSubmit(this)">
|
<form id="js-s2f-form" action="/api/toot" method="POST">
|
||||||
<section>
|
<section>
|
||||||
<label for="text">Post text</label>
|
<label for="text">Post text</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
|
|
@ -32,6 +32,7 @@ const INSTANCE_LIST_URL = "https://api.joinmastodon.org/servers";
|
||||||
const LOCAL_STORAGE_KEY = "recentInstances";
|
const LOCAL_STORAGE_KEY = "recentInstances";
|
||||||
const RECENT_INSTANCES_SIZE = 5;
|
const RECENT_INSTANCES_SIZE = 5;
|
||||||
|
|
||||||
|
const $form = document.querySelector("#js-s2f-form");
|
||||||
const $instance = document.querySelector("#instance");
|
const $instance = document.querySelector("#instance");
|
||||||
const $instanceDatalist = document.querySelector("#instanceDatalist");
|
const $instanceDatalist = document.querySelector("#instanceDatalist");
|
||||||
|
|
||||||
|
@ -110,10 +111,8 @@ function rememberInstance(instance) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used in HTML
|
function onFormSubmit(event) {
|
||||||
// eslint-disable-next-line no-unused-vars
|
const formData = new FormData(event.target);
|
||||||
function onFormSubmit(form) {
|
|
||||||
const formData = new FormData(form);
|
|
||||||
|
|
||||||
if (formData.get("remember")) {
|
if (formData.get("remember")) {
|
||||||
rememberInstance(formData.get("instance"));
|
rememberInstance(formData.get("instance"));
|
||||||
|
@ -140,3 +139,4 @@ if (prefillInstance != undefined) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$instance.addEventListener("focus", loadInstances);
|
$instance.addEventListener("focus", loadInstances);
|
||||||
|
$form.addEventListener("submit", onFormSubmit);
|
||||||
|
|
Reference in a new issue