Skip to content

Commit

Permalink
Merge pull request #81 from yoggys/prevent-multiple-submits
Browse files Browse the repository at this point in the history
fix: prevent multiple submits
  • Loading branch information
sylveon authored Jul 17, 2024
2 parents e699674 + ec46aee commit bad6944
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions public/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ <h2 id="username" class="ml-3 mb-0 align-self-center"></h2>
})

const form = document.querySelector("form");
const button = document.querySelector("button");

form.addEventListener("change", event => {
if (event.target.type === "radio" && event.target.parentElement && event.target.parentElement.tagName.toLowerCase() === "label") {
const prior = form.querySelector('label.checked input[name="' + event.target.name + '"]');
Expand All @@ -108,6 +110,11 @@ <h2 id="username" class="ml-3 mb-0 align-self-center"></h2>
event.target.parentElement.classList.add( "checked" );
}
}, false);

form.addEventListener("submit", () => {
button.disabled = true;
button.textContent = "Submitting...";
}, false);
</script>
</body>
</html>

0 comments on commit bad6944

Please sign in to comment.