Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save somoza/67e5e47c4541a039c49f7d8b5c423fe0 to your computer and use it in GitHub Desktop.
Save somoza/67e5e47c4541a039c49f7d8b5c423fe0 to your computer and use it in GitHub Desktop.
document.addEventListener("DOMContentLoaded", function() {
var elements = document.getElementsByTagName("INPUT");
for (var i = 0; i < elements.length; i++) {
elements[i].oninvalid = function(e) {
e.target.setCustomValidity("");
if (!e.target.validity.valid) {
e.target.setCustomValidity("This field cannot be left blank");
}
};
elements[i].oninput = function(e) {
e.target.setCustomValidity("");
};
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment