0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-10 15:37:30 +00:00
healthchecks_healthchecks/static/js/auto-submit.js
Pēteris Caune decd1d4b87
Improve TOTP auto-submit code
* Listen to "input" event only, don't need "keyup"
* Add form double-submit protection
* Rewrite in plain JS (the page no longer loads jQuery)
2023-11-17 11:00:41 +02:00

15 lines
557 B
JavaScript

window.addEventListener("DOMContentLoaded", function(e) {
var validateAndSubmit = function() {
if (this.validity.valid && !this.dataset.submitted) {
// Make sure we only submit the form once
this.dataset.submitted = true;
this.form.submit();
}
}
// Hook up validateAndSubmit to all input elements with the
// "data-auto-submit" attribute
document.querySelectorAll("input[data-auto-submit]").forEach((input) => {
input.addEventListener("input", validateAndSubmit);
});
});