Skip to content

Instantly share code, notes, and snippets.

@o-nasteka
Created November 20, 2015 21:45
Show Gist options
  • Save o-nasteka/cf87b441f78935a86885 to your computer and use it in GitHub Desktop.
Save o-nasteka/cf87b441f78935a86885 to your computer and use it in GitHub Desktop.
required input Safari
<script type="text/javascript">
function checkForm(){
var forms = document.getElementsByTagName('form');
for (var i = 0; i < forms.length; i++) {
forms[i].noValidate = true;
forms[i].addEventListener('submit', function(event) {
//Prevent submission if checkValidity on the form returns false.
if (!event.target.checkValidity()) {
event.preventDefault();
//Implement you own means of displaying error messages to the user here.
alert('Please, fill the form.');
}
}, false);
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment