Skip to content

Instantly share code, notes, and snippets.

@jaydenseric
Created June 26, 2016 04:20
Show Gist options
  • Save jaydenseric/84d7bf4646ce74a1d78c7fadb090b73b to your computer and use it in GitHub Desktop.
Save jaydenseric/84d7bf4646ce74a1d78c7fadb090b73b to your computer and use it in GitHub Desktop.
Fixes some browsers allowing invalid forms to submit.
// 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.')
}
})
@jaydenseric
Copy link
Author

This has since been fleshed out, given it's own GitHub repo and has been published to NPM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment