DodoApp: Make form disabling logic work with all forms on the page
Change-Id: Ib82aa2fbd9c607fbc373fc0944fd5729813b128e
diff --git a/core/installer/welcome/stat/dodo-app.js b/core/installer/welcome/stat/dodo-app.js
index ccb5252..15e3bb2 100644
--- a/core/installer/welcome/stat/dodo-app.js
+++ b/core/installer/welcome/stat/dodo-app.js
@@ -1,20 +1,16 @@
-function triggerForm(status, buttonTxt) {
- const form = document.getElementById("create-app");
- const elements = form.querySelectorAll("input, select, textarea, button");
- const button = document.getElementById("create-app-button");
- button.textContent = buttonTxt;
- button.setAttribute("aria-busy", status);
- elements.forEach(element => {
- element.disabled = status;
- });
+function makeFormBusyOnSubmit(form, submitter) {
+ submitter.setAttribute("aria-busy", true);
+ form.querySelectorAll("input, select, textarea, button").forEach((element) => {
+ element.disabled = true;
+ });
}
document.addEventListener("DOMContentLoaded", () => {
- const form = document.getElementById("create-app");
+ document.querySelectorAll("form").forEach((form) => {
form.addEventListener("submit", (event) => {
- setTimeout(() => {
- triggerForm(true, "creating app ...");
- }, 0);
- });
- triggerForm(false, "create app");
+ // TODO(gio): Find better way to disable fields
+ setTimeout(() => makeFormBusyOnSubmit(event.target, event.submitter), 0);
+ return true;
+ });
+ });
});