function makeFormBusyOnSubmit(form, submitter) {
  submitter.setAttribute("aria-busy", true);
  form.querySelectorAll("input, select, textarea, button").forEach((element) => {
    element.disabled = true;
  });
}

document.addEventListener("DOMContentLoaded", () => {
  document.querySelectorAll("form").forEach((form) => {
    form.addEventListener("submit", (event) => {
	  // TODO(gio): Find better way to disable fields
	  setTimeout(() => makeFormBusyOnSubmit(event.target, event.submitter), 0);
	  return true;
	});
  });
});

function dropdownSelected(elem, value) {
  while (elem.tagName.toLowerCase() !== "details") {
	elem = elem.parentNode;
  }
  elem.querySelector("summary").innerHTML = value;
  elem.removeAttribute("open");
}
