Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
When using HTML5 forms elements and validation, interrupt a browser's default invalidation message and plug in your own validation code (e.g., append an invalid class to the input and style accordingly).
document.addEventListener('invalid', (function(){
return function(e){
//prevent the browser from showing default error bubble/ hint
e.preventDefault();
// optionally fire off some custom validation handler
myvalidationfunction(e);
};
})(), true);
function myvalidationfunction(e) {
// Do a thing
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment