Skip to content

Instantly share code, notes, and snippets.

@newhope
Created November 21, 2018 07:41
Show Gist options
  • Save newhope/2e91afdc9530d5eb9fed8f764b3908c6 to your computer and use it in GitHub Desktop.
Save newhope/2e91afdc9530d5eb9fed8f764b3908c6 to your computer and use it in GitHub Desktop.
reportValidity polyfill for IE 10, 11
/**
Only work if your form has a submit button
*/
if ( ! HTMLFormElement.prototype.reportValidity) {
HTMLFormElement.prototype.reportValidity = function () {
var validity = this.checkValidity();
if ( ! validity) {
var submitButtons = this.querySelectorAll("button, input[type=submit]");
for (var i = 0; i < submitButtons.length; i++) {
if (submitButtons[i].type === "submit") {
submitButtons[i].click();
return validity;
}
}
}
return validity;
}
}
@mcshaz
Copy link

mcshaz commented Apr 17, 2020

another shot - doesn't matter if a form has multiple submit buttons, does matter if a form has a nosubmit attribute
https://gist.github.com/mcshaz/c65040c11e6daffe356cbedb7ec84ce4

@PFight
Copy link

PFight commented Jul 29, 2020

Thanks, worked for me!

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