Created
November 16, 2020 13:51
-
-
Save czachor/8ccbe075a1eef63b2ad3e53850ccbefd to your computer and use it in GitHub Desktop.
Prevent double submits with javascript - HTML forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.querySelectorAll('form').forEach(form => { | |
form.addEventListener('submit', (e) => { | |
// Prevent if already submitting | |
if (form.classList.contains('is-submitting')) { | |
e.preventDefault(); | |
} | |
// Add class to hook our visual indicator on | |
form.classList.add('is-submitting'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment