Skip to content

Instantly share code, notes, and snippets.

@czachor
Created November 16, 2020 13:51
Show Gist options
  • Save czachor/8ccbe075a1eef63b2ad3e53850ccbefd to your computer and use it in GitHub Desktop.
Save czachor/8ccbe075a1eef63b2ad3e53850ccbefd to your computer and use it in GitHub Desktop.
Prevent double submits with javascript - HTML forms
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