Created
June 26, 2016 04:20
-
-
Save jaydenseric/84d7bf4646ce74a1d78c7fadb090b73b to your computer and use it in GitHub Desktop.
Fixes some browsers allowing invalid forms to submit.
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
// Fixes some browsers allowing invalid forms to submit, mostly an issue with Safari allowing empty required fields. | |
// http://caniuse.com/#search=required | |
window.addEventListener('submit', (event) => { | |
if (!event.target.noValidate && !event.target.checkValidity()) { | |
event.preventDefault() | |
window.alert('Please correct invalid form fields and resubmit.') | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has since been fleshed out, given it's own GitHub repo and has been published to NPM.